I am implementing API that will ahve to handel request - one of them is POST tha will store in it image file (example: jpg) that i will have to upload to azure storage.
I found module, that will alllow putting fiels into storage (seems so, I couldn't try it) if presented as stream or text (so, probably going with stream)
azure-storage
I then used Postman to send request with file: ( Tool for sending multipart/form-data request )
but now, in request's body there is just big mass of incomprehensible characers (seems ok, since it is image), but I stucked now - I do not know how to get that file from reuqest and pass it to module's function?
Some more code:
route.route('/photo')
.post(
(req, res) => {
upload(req);
})
and part for upload(request)
function (now implemented with fucntion useing local file, so I could test if it even worked with connection given - It did!):
process.env.AZURE_STORAGE_CONNECTION_STRING = 'MyConnectionString'
upload(request) {
blobService.createBlockBlobFromLocalFile(
ContaienrName,
FileNameInContainer,
'D:\\My\\Path\\To\\image.jpg',
function (error, result, response) {
if (!error) {
console.log(' >> File uploaded!');
}
else {
console.log(' >> File NOT uploaded!');
}
console.log(' >> --------------------');
console.log(' >> ERROR : ');
console.log(error);
console.log(' >> --------------------');
console.log(' >> RESULT : ');
console.log(result);
console.log(' >> --------------------');
console.log(' >> RESPONSE : ');
console.log(response);
console.log(' >> --------------------');
resolve(resultReturning);
}
);
}
EDIT #1: I managed to get "part" of requst that i will ha ve to handel i nacciuality:
Content-Disposition: form-data; name="image"; filename="71127.jpeg"
Content-Type: image/jpeg