Ad
Can't Download Images From Aws S3 Although All Things Is Correct In Node Js
i use aws-sdk
for download images from aws s3 code no error but no any image download
const filePath = '../imgs';
const bucketName = 'xxx';
const key = "uploads/imgs/logo.png";
const AWS = require('aws-sdk');
AWS.config = new AWS.Config();
AWS.config.accessKeyId = "xxxxxx";
AWS.config.secretAccessKey = "xxxxxxxx";
AWS.config.region = "us-east-1";
const fs = require('fs')
var s3 = new AWS.S3();
const s3download = (bucketName, keyName, localDest) => {
if (typeof localDest == 'undefined') {
localDest = keyName;
}
let params = {
Bucket: bucketName,
Key: keyName
}
let file = fs.createWriteStream(localDest)
return new Promise((resolve, reject) => {
s3.getObject(params).createReadStream()
.on('end', () => {
return resolve();
})
.on('error', (error) => {
return reject(error);
}).pipe(file)
});
};
s3download(bucketName, key, filePath)
when print result appear this
_readableState: ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
pipes: [],
flowing: null,
ended: false,
endEmitted: false,
reading: false,
sync: false,
needReadable: false,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
errorEmitted: false,
emitClose: true,
autoDestroy: true,
destroyed: false,
errored: false,
closed: false,
closeEmitted: false,
defaultEncoding: 'utf8',
awaitDrainWriters: null,
multiAwaitDrain: false,
readingMore: false,
decoder: null,
encoding: null,
[Symbol(kPaused)]: null
},
_events: [Object: null prototype] { prefinish: [Function: prefinish] },
_eventsCount: 1,
_maxListeners: undefined,
_writableState: WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: true,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: true,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
afterWriteTickInfo: null,
buffered: [],
bufferedIndex: 0,
allBuffers: true,
allNoop: true,
pendingcb: 0,
prefinished: false,
errorEmitted: false,
emitClose: true,
autoDestroy: true,
errored: false,
closed: false,
closeEmitted: false
},
allowHalfOpen: true,
[Symbol(kCapture)]: false,
[Symbol(kCallback)]: null
}
Ad
Answer
filePath
provides the path to the folder where we want to save the file that we get from S3 but we do not provide a filename here:
let file = fs.createWriteStream(localDest)
localDest
should be a full-path + filename and currently it only provides the full path
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad