开发者社区> 问答> 正文

阿里云 oss 断点续传报错404?

使用阿里云分片和断点上传一直报错 image.png image.png

翻译过来说是id image.png

function upload (event) {
  return new Promise((resolve, reject) => {
    client = new OSS({
      region: OSSConfig.ossParams.region,
      accessKeyId: OSSConfig.ossParams.accessKeyId,
      accessKeySecret: OSSConfig.ossParams.accessKeySecret,
      bucket: OSSConfig.ossParams.bucket,
      timeout: 120000 
    })
    let file = event
    let randomName = `${OSSConfig.ossParams.path}${file.uid}`
    co(function* () {
    //   let result = yield client.multipartUpload(randomName, file)
    let result = yield client.multipartUpload(randomName, file, {
        parallel,
        partSize,
        progress: onMultipartUploadProgress
      })
      console.log(result, 'result.name');
      resolve(`${OSSConfig.uploadHost}/${result.name}`)
    }).catch(function (err) {
      reject(err)
    })
  })
}
async function onMultipartUploadProgress(progress, checkpoint) {
    console.log(progress, checkpoint);
    // console.log(`${checkpoint.file.name} 上传进度 ${progress}`);
    // 上传进度
    // window.$progress = progress;
    checkpoints[checkpoint.uploadId] = checkpoint;
    // const { Expiration } = credentials;
    // console.log(credentials);
    await resumeMultipartUpload();
  }

  // 断点续传
async function resumeMultipartUpload() {
    Object.values(checkpoints).forEach((checkpoint) => {
      const { uploadId, file, name } = checkpoint;
      console.log(file, 'uploadId')
      client.multipartUpload(uploadId, file, {
        parallel,
        partSize,
        progress: onMultipartUploadProgress,
        checkpoint
      }).then(result => {
        // console.log('before delete checkpoints === ', result);
        client.cancel();
        delete checkpoints[checkpoint.uploadId];
        console.log('after delete checkpoints === ', name);
        // const url = `http://${bucket}.${region}.aliyuncs.com/${name}`;
        // console.log(`Resume multipart upload ${file.name} succeeded, url === `, url)
      }).catch(err => {
        // client.cancel();
        // window.$cancelBoolean = true;
        console.log(err);
      });
    });
  }

展开
收起
wllei0618 2020-04-06 16:45:28 1222 0
1 条回答
写回答
取消 提交回答
  • 技术架构师 阿里云开发者社区技术专家博主 CSDN签约专栏技术博主 掘金签约技术博主 云安全联盟专家 众多开源代码库Commiter

    触发的上传已经关闭了。

    2020-04-07 22:45:32
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
OSS运维进阶实战手册 立即下载
《OSS运维基础实战手册》 立即下载
OSS运维基础实战手册 立即下载