symphonicc / multer-azure-blob-storage

ES6 & Typescript friendly multer storage engine for Azure's blob storage.
MIT License
19 stars 25 forks source link

Size of file is 0 when file.stream is manipulated before upload #35

Closed vicmpen closed 5 months ago

vicmpen commented 5 months ago

Hello and thanns for the package. Here is my question.

We use the package successfully. Upload works fine. We had a request to save the video duration on the database when the file is uploaded. For this, we added code to the MASObjectResolver of MulterAzureStorage.

Before returning the metadata object, we convert the stream to a buffer and caclculate the duration of the video with a helper function. When we do this, the file is uploaded with size of 0. When we skip the duration caclulation, the file is uploaded normally.

As i take it, with my very limited experience, once the stream is somehow used it is also consumed, or something along those lines.

Could you give me some directions of how to accomplish this, as our last resort which is uploading the file and then downloading it againt to caclulate the duration is far from good.

In general, is there any way to get hold of the file raw data before or after uploading?

Thanks a lot, and once again thanks for your work.

vicmpen commented 5 months ago

Well, i managed to do it by piping the fileStream to the disk and reading it at a later time.