2017-12-14 9 views
1

amazon s3에서 파일을 업로드 할 때 오류가 발생합니다. 다음과 같이 코드는 다음과 같습니다Amazon S3에서 노드 파일 업로드 오류가 발생했습니다.

 const s3 = require('s3'); const client = s3.createClient({ 
      maxAsyncS3: 100, 
      s3RetryCount: 3, 
      s3RetryDelay: 30000, 
      multipartUploadThreshold: 20971520, 
      multipartUploadSize: 15728640, 
      s3Options: { 
       accessKeyId: "xxxx", 
       secretAccessKey: "yyyy", 
       region: "us-east-2", 
      }, }); 
      const params = { 
      localDir: "file-path", 
      s3Params: { 
       Bucket: "bucket-name", 
       Prefix: "images/image.jpg" 
      }, };  
      const uploader = client.uploadDir(params); 
     uploader.on('error', (err) => { 
      console.error("unable to upload:", err.stack); 
     });  
uploader.on('progress',() => { 
      console.log("progress", uploader.progressMd5Amount, 
         uploader.progressAmount, uploader.progressTotal); });  
uploader.on('end',() => { 
      console.log("done uploading"); }); 

I가 얻을 오류를 :

unable to upload: Error: Non-file stream objects are not supported with SigV4 in AWS.S3

+0

내가 항상 사용 AWS는 S3 서버와 이야기 SDK 다음은 예입니다. 나는 s3 라이브러리를 모르지만 잘못 읽은 메시지에서 그가 경로 대신에 스트림을 기대하고있는 것 같습니다. localdir : 'file-path'를 localdir : fs.createReadStream ('filepath')으로 변경하십시오. 나는 그것이 효과가 있을지 모른다. 내가 말했듯이, 나는 s3 라이브러리를 모른다. – Radar155

답변

0

당신은 업로드 방법에게 파일을 전달해야합니다. 에서

var file = files[0]; 
    var fileName = file.name; 
    var albumPhotosKey = encodeURIComponent(albumName) + '//'; 

    var photoKey = albumPhotosKey + fileName; 
    s3.upload({ 
    Key: photoKey, 
    Body: file, 
    ACL: 'public-read' 
    }, function(err, data) { 
    if (err) { 
     return alert('There was an error uploading your photo: ', err.message); 
    } 
    alert('Successfully uploaded photo.'); 
    viewAlbum(albumName); 
    }); 
} 

더 많은 예제 : http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/s3-example-photo-album-full.html