multer icon indicating copy to clipboard operation
multer copied to clipboard

Disable automatic upload or upload after data validation

Open Kayoshi-dev opened this issue 4 years ago • 3 comments

Hello,

I know this is maybe not the best place to post that question but I've already checked and posted a question on stackoverflow, without any answers (same for the people that posted the same question).

What I would like to achieve is basically a data validation before the image get uploaded on the server.

I think it makes no sense to upload the image before doing the data validation as my stockage would be full of useless pictures.

Is it possible with multer? And if so, how would you do that? Thanks a lot!

Kayoshi-dev avatar Nov 13 '21 22:11 Kayoshi-dev

There is not enough information for me to answer this question here. What kind of validation are you doing? What do you mean by "uploading" the image? To your server? What data is it that you want to validate?

The browser sends a stream of fields and files with no particular ordering, so usually the files will have to be received before you can read all the field data though...

LinusU avatar Nov 16 '21 14:11 LinusU

There is not enough information for me to answer this question here. What kind of validation are you doing? What do you mean by "uploading" the image? To your server? What data is it that you want to validate?

The browser sends a stream of fields and files with no particular ordering, so usually the files will have to be received before you can read all the field data though...

I have the same issue, possibly. Also can't find any help with this.

Some validation before upload would be helpful. Particularly in my case, I'd like to check if the file exists on the server already before the upload. I have tried in the destination part of file storage but the only option I get is a callback error or filename and if I throw an error the server stops. I'd like to check to see if the file exists before upload and write to database, then and only after a check, I upload the file.

I tried creating some middleware before the upload middleware but the file doesn't exist on the request yet so it was impossible

Any help would be appreciated

mikevarela avatar Nov 19 '21 01:11 mikevarela

I see, I don't think that there is great support for this at the moment. You could either use your own storage engine (and delegate the actual storing to the built in one), or you could try using the release candidate of v2.x of Multer which would give you file streams directly on the req object 🙌

LinusU avatar Nov 19 '21 09:11 LinusU