通过放大存储 reactjs 在 S3 上上传时出错

Error uploading on S3 through amplify storage reactjs

我使用的是最新版本 aws/amplify 3.3.7

这是代码

const s3Upload = async (file, id) => { 
    const filename = file.name.replace(/\s/g, '') 
    await Storage.vault.put(filename, file, { 
      contentType: file.type 
   })
}

当我尝试上传小文件(1 Mb zip 文件)时,它工作正常,但是当我尝试上传更大的文件(即 6 Mb zip 文件)时,出现错误:

AWSS3ProviderManagedUpload - error happened while finishing the upload. Cancelling the multipart upload Error: Request failed with status code 40

有人遇到过这个问题

我一直遇到同样的问题,在大约 5MB 后,Amplify 使用分段上传但失败并出现相同的错误。

我的解决方法是 https://github.com/aws-amplify/amplify-js/issues/61

我在 S3 存储桶的 CORS 设置中将 ETag 添加到 ExposeHeaders,之后上传 10 MB 的文件时效果很好。