使用 Ajax 请求将文件上传到 BackBlaze (B2) 时出现校验和错误

问题描述

我花了很多时间尝试使用客户端 ajax 请求 (vue-dropzone.js) 将文件上传到 b2,即使我提供了文件的有效 sha1 校验和,b2 服务器仍然响应“校验和没有收到匹配数据”,状态代码为 400。我已经使用我拥有的所有工具检查并重新检查了校验和,但我仍然无法追踪错误的来源。就好像文件在传输过程中发生了什么事情一样。

我已经使用命令行工具上传了相同的文件并且运行良好,但是当我使用完全相同的 sha1 校验和通过 ajax 上传时它不起作用。

我的问题是:

  1. b2 甚至允许通过 ajax 上传文件吗?

  2. 如果它允许通过 ajax 上传,那么我做错了什么?

  3. 使用“X-Bz-Content-Sha1”、“do_not_verify”上传文件是否仍然有效。因为我试过这样做只是为了在我下载回无效文件获取它们。

  4. 关于使用 ajax 请求将文件上传到 b2,我还有其他需要了解的事情吗

请查看我的 ajax 代码,看看我是否有任何错误

             sending(file,xhr,formData) {
                // This function runs for each file right before they are sent by dropezone.
                // This is a good opportunity to insert file specific values
                // in this case the file's upload url,name and auth token
                let fileName = '';
                console.log('this is file type',file.type);
                if (file.type.includes('image')) {
                    fileName = 'images/${uuid.v1()}.png';
                } else if (file.type.includes('video')) {
                    fileName = 'videos/${uuid.v1()}.${file.type.split(' / ')[1]}';
                }
    
                const url = appConfig.serverAddress + '/catalog/submitFiles';
                console.log('this is sha1_hash',this.uploadInfo.sha1_hash);
                // open the xhr request and insert the file's upload url here
                xhr.open('Post',this.uploadInfo.url,true);
    
                // set b2's mandatory request headers
                // xhr.setRequestHeader(
                //  'Authorization',//  'Bearer ' + store.getters.getUserIdToken,// );
                xhr.setRequestHeader('Authorization',this.uploadInfo.authorizationToken);
                xhr.setRequestHeader('X-Bz-Content-Sha1',this.uploadInfo.sha1_hash);
                xhr.setRequestHeader('X-Bz-File-Name',fileName);
                xhr.setRequestHeader('Content-Type','b2/x-auto');
    
                formData = new FormData();
                formData.append('files',file);
    
                // the rest will be handled by dropzones upload pipeline
            }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)