Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ajax 连接到S3时出错复位_Ajax_Amazon S3_Xmlhttprequest - Fatal编程技术网

Ajax 连接到S3时出错复位

Ajax 连接到S3时出错复位,ajax,amazon-s3,xmlhttprequest,Ajax,Amazon S3,Xmlhttprequest,我通过ajax请求将文件放入S3,大约50%的时间我会收到ERR\u CONNECTION\u RESET错误 我知道请求的签名是正确的,你知道是什么原因造成的吗?同样,这是一个间歇性问题,我从多个位置和机器上看到 下面是我用来将文件放入S3的相关coffeescript代码。它来源于Micah Roberson和Rok Krulec在和的工作 更新 在这个问题上,我得到了亚马逊非常周到的支持。根据他们的建议,我创建了一个EC2 Windows实例,在上面加载了Chrome浏览器,并尝试用我的代

我通过ajax请求将文件放入S3,大约50%的时间我会收到ERR\u CONNECTION\u RESET错误

我知道请求的签名是正确的,你知道是什么原因造成的吗?同样,这是一个间歇性问题,我从多个位置和机器上看到

下面是我用来将文件放入S3的相关coffeescript代码。它来源于Micah Roberson和Rok Krulec在和的工作

更新

在这个问题上,我得到了亚马逊非常周到的支持。根据他们的建议,我创建了一个EC2 Windows实例,在上面加载了Chrome浏览器,并尝试用我的代码上传5个文件10次。我一次也没有看到这个错误。我确实偶尔看到一些SignatureedesNotMatch错误,但没有一个错误\u连接\u重置错误。尽管在我使用的每个非EC2客户端/网络位置上,我仍然看到错误连接重置错误


更新这里仍然没有解决方案。我已经从使用自滚动签名算法转变为boto提供的算法。但对错误连接重置问题没有影响。

我最终放弃了让它工作。相反,我现在使用来提供此功能。

我想这个问题没有决定权

尝试POST请求:


要上载到S3的文件:

如果您喜欢AJAX发送,请使用附加字段


要在nodejs中对请求进行签名:

我在上载带有预签名URL的较大文件(长请求)时遇到了这个问题,如下所示(node aws sdk):

“Expires”参数使签名的URL有效期为60秒

我想,当在上传的过程中签名的URL过期(即使上载启动时是有效的)时,请求会崩溃。

但它不会在60秒后完全崩溃,而是在60到120秒之间随机崩溃。大多数情况下,客户端会记录ERR_CONNECTION_RESET,其他情况下会记录403 probled

把它调高到3600后,我再也没有问题了


我怀疑这个问题没有发生在EC2上,因为它们的上传速度非常快。

我也遇到了同样的问题!我使用的是同一组资源(博客和模型代码),结果完全相同。大约有一半的时间,请求会在没有其他信息的情况下重置错误连接。谢谢Joan。关于AWS,我有一个积极的问题,但这需要我将浏览器代码复制为一个独立的过程,以便进行调试——这需要一些开发。如果您需要帮助为AWS组装一些东西,请告诉我。我越早把事情弄清楚越好。如果有用的话,我很乐意与您一起使用github(或替代品)。我只想添加一个+1。我也遇到了同样的问题,主要是为了从Angular/coffeescript前端下载我的Django应用程序。添加了更新--将EC2实例用作客户端时没有错误。该应用程序已不再有效:-(
  createCORSRequest: (method, url) ->
    xhr = new XMLHttpRequest()

    if xhr.withCredentials?
      xhr.open method, url, true
    else if typeof XDomainRequest != "undefined"
      xhr = new XDomainRequest()
      xhr.open method, url
    else
      xhr = null

    xhr

  uploadToS3: (file, signature) ->
    this_s3upload = this
    this_s3upload.signature = signature
    url = signature.signed_request

    xhr = @createCORSRequest 'PUT', decodeURIComponent(signature.signed_request)

    if !xhr
      @onError 'CORS not supported'
    else
      xhr.onload = () ->
        if xhr.status == 200
          this_s3upload.onProgress 100, 'Upload completed.'
          this_s3upload.onFinishS3Put file, this_s3upload.signature
        else
          this_s3upload.onError file, 'Upload error: ' + xhr.status

      xhr.onerror = () ->
        this_s3upload.onError file, 'XHR error.', this_s3upload.signature

      xhr.upload.onprogress = (e) ->
        if e.lengthComputable
          percentLoaded = Math.round (e.loaded / e.total) * 100

          if percentLoaded == 100
            message = "Finalizing"
          else
            message = "Uploading"

          this_s3upload.onProgress xhr, file, percentLoaded, message, this_s3upload.signature

      xhr.onabort = ->
        this_s3upload.onAbort file, "XHR cancelled by user.", this_s3upload.signature

    xhr.setRequestHeader 'Content-Type', file.type
    xhr.setRequestHeader 'x-amz-acl', 'public-read'
    xhr.send file
<form action="https://s3-bucket.s3.amazonaws.com/" method="post" enctype="multipart/form-data">
  <input type="hidden" name="key" value="uploads/${filename}">
  <input type="hidden" name="AWSAccessKeyId" value="YOUR_AWS_ACCESS_KEY"> 
  <input type="hidden" name="acl" value="private"> 
  <input type="hidden" name="success_action_redirect" value="http://localhost/">
  <input type="hidden" name="policy" value="YOUR_POLICY_DOCUMENT_BASE64_ENCODED">
  <input type="hidden" name="signature" value="YOUR_CALCULATED_SIGNATURE">
  <input type="hidden" name="Content-Type" value="image/jpeg">
  <!-- Include any additional input fields here -->

  File to upload to S3: 
  <input name="file" type="file"> 
  <br> 
  <input type="submit" value="Upload File to S3"> 
</form> 
app.get('/sign-s3', (req, res) => {
  const s3 = new aws.S3();
  const fileName = req.query['file-name'];
  const fileType = req.query['file-type'];
  const s3Params = {
    Bucket: S3_BUCKET,
    Key: fileName,
    Expires: 60,
    ContentType: fileType,
    ACL: 'public-read'
  };

  s3.getSignedUrl('putObject', s3Params, (err, data) => {
    if(err){
      console.log(err);
      return res.end();
    }
    const returnData = {
      signedRequest: data,
      url: `https://${S3_BUCKET}.s3.amazonaws.com/${fileName}`
    };
    res.write(JSON.stringify(returnData));
    res.end();
  });
});