ERR_CONNECTION_RESET将大文件上载到Amazon S3时出错

Dev*_*mar 6 file-upload heroku amazon-s3 amazon-web-services node.js

我正在关注本教程:

https://devcenter.heroku.com/articles/s3-upload-node

使用NodeJS和Jquery将文件上传到Amazon s3.它适用于小图像和文件.但是它会产生XHR连接RESET错误.

我的CORS配置看起来完全像这样:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
   <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?

小智 2

如果您按照heroku文档中给出的说明进行操作,您将看到一行

  const s3Params = {
Bucket: S3_BUCKET,
Key: fileName,
Expires: 60,
ContentType: fileType,
ACL: 'public-read'};
Run Code Online (Sandbox Code Playgroud)

正如您在此 aws 文档中所看到的,过期元数据意味着预签名 URL 操作过期的秒数。这里给出的是 60,等于 1 分钟。在 60 秒内上传大文件。不可能。

修复:尝试从 s3Params 中删除过期元数据或增加该值。默认情况下,预签名 URL 将在 15 分钟后过期。

现在你的代码将如下所示:

  const s3Params = {
Bucket: S3_BUCKET,
Key: fileName,
ContentType: fileType,
ACL: 'public-read'};
Run Code Online (Sandbox Code Playgroud)