2***@qq.com
2***@qq.com
  • 发布:2020-06-14 21:19
  • 更新:2020-07-07 21:11
  • 阅读:2124

uniCloud.deleteFile 报错,不允许被访问

分类:uniCloud

上传文件没问题,但删除文件的时候就报错,提示不允许被访问。。。

通过API上传的文件无法通过API删除,但手动在云存储上传的文件又可以通过API删除。。奇怪了

        methods: {  
            uploadFile() {  
                uni.chooseImage({  
                    count: 1,  
                    async success(res) {  
                        console.log(res);  
                        if (res.tempFilePaths.length > 0) {  
                            let filePath = res.tempFilePaths[0]  
                            //进行上传操作  

                            // promise  
                            const result = await uniCloud.uploadFile({  
                                filePath: filePath  
                            });  
                        }  
                    }  
                });  
            },  
            deleteFile() {  
                // 删除文件  
                uniCloud  
                    .deleteFile({  
                        fileList: ['https://vkceyugu.cdn.bspapp.com/VKCEYUGU-uni6b36bd0/177b5b20-ae48-11ea-b680-7980c8a877b8.png']  
                    })  
                    .then(res => {});  
            }  
        }

{err: Error: 不允许访问
at Function.complete (webpack-internal:///./node_modules/@dcloudio/vue-cli-plugin-…}
err: Error: 不允许访问 at Function.complete (webpack-internal:///./node_modules/@dcloudio/vue-cli-plugin-uni/packages/uni-cloud/dist/index.js:2:8510) at eval (webpack-internal:///./node_modules/@dcloudio/uni-h5/dist/index.umd.min.js:1:67014) at Object.j [as callback] (webpack-internal:///./node_modules/@dcloudio/uni-h5/dist/index.umd.min.js:1:69918) at v (webpack-internal:///./node_modules/@dcloudio/uni-h5/dist/index.umd.min.js:1:70440) at XMLHttpRequest.y.onload (webpack-internal:///./node_modules/@dcloudio/uni-h5/dist/index.umd.min.js:1:41648)
errMsg: "不允许访问"
code: "PolicyDenied"
message: "不允许访问"
requestId: undefined
stack: "Error: 不允许访问↵ at Function.complete (webpack-internal:///./node_modules/@dcloudio/vue-cli-plugin-uni/packages/uni-cloud/dist/index.js:2:8510)↵ at eval (webpack-internal:///./node_modules/@dcloudio/uni-h5/dist/index.umd.min.js:1:67014)↵ at Object.j [as callback] (webpack-internal:///./node_modules/@dcloudio/uni-h5/dist/index.umd.min.js:1:69918)↵ at v (webpack-internal:///./node_modules/@dcloudio/uni-h5/dist/index.umd.min.js:1:70440)↵ at XMLHttpRequest.y.onload (webpack-internal:///./node_modules/@dcloudio/uni-h5/dist/index.umd.min.js:1:41648)"
get code: ()=>e.code
get message: ƒ get()
set message: ƒ set(e)
get requestId: ()=>e.requestId
proto: Error
proto: Object

2020-06-14 21:19 负责人:无 分享
已邀请:
zarkk

zarkk - alex

同样的代码,前几天还好好的,今天我也遇到了这个问题

DCloud_uniCloud_WYQ

DCloud_uniCloud_WYQ

客户端删除云存储文件需要注意权限,最好是能使用自定义登录 https://uniapp.dcloud.io/uniCloud/authentication ,确保上传文件和删除文件的是同一个人才允许客户端删除文件。你之前匿名上传的在当时可以删除但是换了另外一个匿名身份之后就不可以了

  • zarkk

    uniCloud.auth() 明明写着只支持腾讯云,而我用的阿里云

    2020-06-15 21:41

  • 2***@qq.com (作者)

    回复 zarkk: 我也是阿里云

    2020-06-16 08:04

  • DCloud_uniCloud_WYQ

    回复 2***@qq.com: 如果是阿里云的话不应该依赖客户端删除文件

    2020-06-16 12:20

离之歌

离之歌

问题解决了吗?我也出现这个问题了

4***@qq.com

4***@qq.com

open(){
// callback
uniCloud.deleteFile(
{
fileList: ['https://vkceyugu.cdn.bspapp.com/VKCEYUGU-testuni-app/104325ab-5982-44ca-b4e0-673c9a25f3e0.jpg'],
success(res){console.log(res)},
fail(err){console.log(err)},
complete(){}
}
);
}
报错:啥情况
Error: delete_file_no_permission https://vkceyugu.cdn.bspapp.com/VKCEYUGU-testuni-app/104325ab-5982-44ca-b4e0-673c9a25f3e0.jpg
at complete (index.js?a9ff:1)
at Object.i.complete.i.complete (VM81 WAService.js:2)
at VM81 WAService.js:2
at Module.s (VM81 WAService.js:2)
at Function.<anonymous> (VM81 WAService.js:2)
at h (VM81 WAService.js:2)
at VM81 WAService.js:2
at k (VM81 WAService.js:2)
at Function.<anonymous> (VM81 WAService.js:2)
at h (VM81 WAService.js:2)

  • 1***@qq.com

    大神,我遇到了同样的问题,请问你怎么解决的

    2020-07-25 23:08

DCloud_uniCloud_WYQ

DCloud_uniCloud_WYQ

使用阿里云时请使用云函数删除文件

  • 吴克

    云函数怎么获取文件id,不然请求的路径发什么都不知道

    2021-06-29 19:53

该问题目前已经被锁定, 无法添加新回复