小编nbp*_*pp2的帖子

使用签名网址将文件从angularjs直接上传到amazon s3

所以我在将文件直接上传到S3时遇到了一些麻烦.目前我的流程是向nodejs/express发出请求以获取签名的URL.

app.post('/s3SignedURL', function(req, res){
  var id = crypto.randomBytes(20).toString('hex');
  var ext = path.extname(req.body.fileName);
  var unambFilename = path.basename(req.body.fileName, ext) + '-' + id + ext;
  var params = {Bucket: awsBucket, Key: unambFilename, Expires: 30};
  var signedUrl = s3.getSignedUrl('putObject', params);

  res.send({signedUrl: signedUrl, s3FileName: unambFilename});
});
Run Code Online (Sandbox Code Playgroud)

我的角度控制器然后尝试使用该签名URL直接上传到s3($ scope.uploadDocument())

flqApp.controller('DocUploadModalCtrl', ['$scope', '$http', 'customProvider', 'custom',
  function($scope, $http, customProvider, custom){

  $scope.fileTypes = 
  [
    "Type 1",
    "Type 2"
  ]

  $scope.setFile = function(element){
    $scope.$apply(function($scope){
      $scope.currentDocument = element.files[0];
    });
  }

  $scope.uploadDocument = function() {
    $http.post('/s3SignedURL', {fileName: $scope.currentDocument.name} )
     .success(function(results){
      $http.put(results.signedUrl, …
Run Code Online (Sandbox Code Playgroud)

amazon-s3 cors angularjs

10
推荐指数
2
解决办法
9130
查看次数

标签 统计

amazon-s3 ×1

angularjs ×1

cors ×1