2
以下是我的節點JavaScript代碼,用於使用s3fs
庫將圖像上傳到Amazon S3。圖像正確上傳,但是當我嘗試在瀏覽器中查看該圖像時,它提供了下面提到的錯誤。節點js s3fs圖像上傳到aws amazon s3服務器並設置ContentType
我檢查了內容類型,默認保存爲octet-stream
。如果我手動將其設置爲image/jpeg
,那麼該圖像可在瀏覽器中查看。任何人都可以告訴我只能在上傳完成後才能設置Content-Type嗎?
我試圖設置內容類型,但它不工作S3fs
圖像上傳。
錯誤代碼: -
<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
</Error>
我的實際代碼: -
var AWS= require('aws-sdk');
var fs = require('fs');
var S3FS = require('s3fs');
var s3fsImpl = new S3FS('bbqmobileimages/images/banners',{
accessKeyId:'A********A',
secretAccessKey:'****************'
});
var multiparty = require('connect-multiparty'),
multipartyMiddleware = multiparty();
router.use(multipartyMiddleware);
router.post('/api/v1/backoffice/upload/image',function(req,res){
console.log(JSON.stringify(req.files));
var file = req.files;
console.log("file",JSON.stringify(file))
console.log("original name:- "+file.fileUpload.originalFilename);
console.log("Path:- ",file.fileUpload.path);
var stream = fs.createReadStream(file.fileUpload.path);
return s3fsImpl.writeFile(file.fileUpload.originalFilename, stream).then(function(){
fs.unlink(file.fileUpload.path, function(err){
console.error(err);
})
console.log("Sucessfully uploaded to Amazon S3 server");
});
});
謝謝哥們其工作的罰款(Y) –
@HemantNa garkoti如果我的回答對您有幫助,請點擊左側的複選標記並將我的答案標記爲正確。 – Houseman