0

내 웹 사이트의 이미지 (PNG)를 S3에 업로드하려고합니다.웹 사이트에서 S3으로 파일 업로드

람다에게 multipart/form-data 요청을 보내고 Busboy를 사용하여 파싱합니다.

그것은 잘 S3에 업로드되는 동영상과 이미지/PNG는 것을 알 수 있지만 파일을 다운로드하여 볼하려고하면 파일이

가 무슨 원인이 될 수 무효? 내가 어디서 잘못 될지는 모르겠다.

코드 : 사전에

var AWS = require('aws-sdk'); 
var BluebirdPromise = require("bluebird"); 
var Busboy = require('busboy'); 
var s3 = BluebirdPromise.promisifyAll(new AWS.S3()); 
var str = require('string-to-stream'); 

const SavePFP = async((user_id, req) => { 
    var busboy = new Busboy({headers: req.headers}); 

    let res = await(new Promise((resolve) => { 
     busboy.on('file', function (fieldname, file, filename, encoding, mimetype) { 
      console.log('File [' + fieldname + ']: filename: ' + filename); 

      file.on('data', function (data) { 
       console.log('File [' + fieldname + '] got ' + data.length + ' bytes'); 

       resolve({ 
        filename, 
        encoding, 
        mimetype, 
        data 
       }); 
      }); 

      file.on('end', function() { 
       console.log('File [' + fieldname + '] Finished'); 
      }); 
     }); 

     str(req.rawBody).pipe(busboy); 
    })); 

    let {data, encoding, mimetype} = res; 

    var params = { 
     Bucket: '...', 
     Key: user_id, 
     Body: data, 
     ACL: 'public-read', 
     ContentEncoding: encoding, 
     ContentType: mimetype 
    }; 

    console.log("Uploading to AWS S3..."); 
    let response = await(s3.upload(params).promise()); 
    console.log("[SavePFP]: " + JSON.stringify(response, null, 2)); 

    if (response && response.Location) { 
     return response.Location; 
    } 
}); 

module.exports = { 
    SavePFP 
}; 

감사합니다!

답변

0

파일을 base64로 변환하고 거기에서 업로드하여이 문제를 해결하지 않았습니다.

감사합니다.