s3 upload as stream using req stream (extra info in request header)
const file = this.input.files[0]; | |
//console.log(file); | |
var xhr = new XMLHttpRequest(); | |
xhr.addEventListener('load', (e) => { | |
console.log(e.target.response); | |
}); | |
xhr.open('POST', host + 'fileuploadstream', true); | |
xhr.setRequestHeader('body', JSON.stringify({ id: 'somebucketfolderid', fn: file.name })); | |
xhr.send(file); |
const fileUploadStream = (req, res) => { | |
//get "body" args from header | |
const { id, fn } = JSON.parse(req.get('body')); | |
const Key = id + '/' + fn; //upload to s3 folder "id" with filename === fn | |
const params = { | |
Key, | |
Bucket: bucketName, //set somewhere | |
Body: req, //req is a stream | |
}; | |
s3.upload(params, (err, data) => { | |
if (err) { | |
res.send('Error Uploading Data: ' + JSON.stringify(err) + '\n' + JSON.stringify(err.stack)); | |
} else { | |
res.send(Key); | |
} | |
}); | |
}; |
This comment has been minimized.
This comment has been minimized.
@spsneo are you using express bodyParser? using that might remove req.files |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
This does not work properly with express. Am I missing something?