当达到12MB的已加载数据时,AWS S3 Multipart上传重新启动

时间:2016-03-30 00:36:48

标签: amazon-web-services amazon-s3

我在角度应用程序中使用AWS S3 Multipart努力上传文件。上传开始但在达到12 MB加载数据后重新启动。

日志

Object {loaded: 12582912, total: 91015730, part: 3, key: "IMG_2973.MOV"}
postVideo.js:46 14% done
postVideo.js:47 Object {loaded: 12582912, total: 91015730, part: 4, key: "IMG_2973.MOV"}
postVideo.js:46 8% done
postVideo.js:47 Object {loaded: 7684096, total: 91015730, part: 2, key: "IMG_2973.MOV"}
postVideo.js:46 7% done
postVideo.js:47 Object {loaded: 6078464, total: 91015730, part: 4, key: "IMG_2973.MOV"}
postVideo.js:46 4% done
postVideo.js:47 Object {loaded: 3850240, total: 91015730, part: 3, key: "IMG_2973.MOV"}
postVideo.js:46 1% done
Object {loaded: 589824, total: 91015730, part: 1, key: "IMG_2973.MOV"}
postVideo.js:46 1% done
postVideo.js:47 Object {loaded: 622592, total: 91015730, part: 4, key: "IMG_2973.MOV"}
postVideo.js:46 1% done
postVideo.js:47 Object {loaded: 655360, total: 91015730, part: 3, key: "IMG_2973.MOV"}
postVideo.js:46 1% done

应用程序重试几次,但随后会超时。

我在这里几乎迷失了,任何想法都会有所帮助。

CORS

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>POST</AllowedMethod>
        <ExposeHeader>x-amz-server-side-encryption</ExposeHeader>
        <ExposeHeader>x-amz-request-id</ExposeHeader>
        <ExposeHeader>x-amz-id-2</ExposeHeader>
        <ExposeHeader>ETag</ExposeHeader>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

$scope.upload = function() {
    // Configure The S3 Object 
    $scope.creds = $publisherServices.getAwsCreds();
    AWS.config.update({ accessKeyId: $scope.creds.access_key, secretAccessKey: $scope.creds.secret_key });
    //AWS.config.region = 'sa-east-1';
    var bucket = new AWS.S3({apiVersion: '2006-03-01', params: {Bucket: $scope.creds.bucket}});

    if($scope.file) {
      var params = { Key: $scope.file.name, ContentType: $scope.file.type, Body: $scope.file};
      bucket.upload(params).
        on('httpUploadProgress', function(progress) {
          console.log(Math.round(progress.loaded / progress.total * 100) + '% done');
          console.log(progress);
        }).send(function(err, data) { console.log(err, data) });
    } else {
      // No File Selected
      alert('No File Selected');
    }
  }

1 个答案:

答案 0 :(得分:3)

topic opened in aws-sdk-js github的帮助下,我能够解决问题。事实是,为部件预先配置了2分钟的超时。

要禁用它,只需设置httpOptions超时:

var bucket = new AWS.S3({
  apiVersion: '2006-03-01', 
  httpOptions: {timeout: 0}, 
  params: {Bucket: $scope.creds.bucket}
});