#Nestjs-form-data not serializing.
25 messages · Page 1 of 1 (latest)
try with raw, json
I will upload a file sometimes
multer doesn't automatically parse the data the same way json will. You'll need some custom @Transform()s for that
yeah but nestjs-form-data package provides that feature, does not?
Not sure honestly. Looks like it uses append-field, so it might depend on how that librarty works. Never worked with nestjs-form-data to be honest
i've been using nestjs- form-data in my project as well and what i've figured is that when doing the request as multipart/form-data all values will be received as strings and you have to use @Transform() to handle them in your DTO.
i'm not sure if thats an issue with the library or if its just how multipart/form-data works tbh
Thanks, I'm trying this, but how to transform an array?
How do you send it, how does it come in?
Remove the validation momentarily to see what the data looks like after busboy parses it
I believe a JSON.parse() will do for that
It's done, thanks for help.
But how it's usually manages file uploads with other types of data. In a single request or multiple (json)?
Most people I know try to avoid multi file uploads for the complexity of it, but it is a valid use case, so it all just depends
is there any option to upload files?
What do you mean?
that it is easier for validations
Your issue is with how multipart/form-data is parsed. These parsers really exist to handle the binary data of forms and treat absolutely everything as strings. I've not looked into if there is a parser that treats binary as binary and everything else parsed into a JS type like you're wanting
But good news, this workaround exists, and it's honestly not too complex
ah okay I understand, thanks for help.
@wary flame kinda related to this, how would you recommend dealing with an album picture type thing where a user could upload one or more files?
avoid doing multi file upload on one request and instead do one request for each file?
It depends on how you want to do the files. Does each file have it's own name and description? Are you just adding a name and description for the album instead? Uploading multiple files at once isn't impossible, nor is it bad, the "difficult" thing is bulk upload of multiple objects with multiple files, because of the way multipart data is formed
i see
in this scenario the album would have its own name and description and the files don't have their own info. im currently doing it with nestjs-form-data and uploading multiple files at once but was just curious if there was a better/more recommended way of dealing with these situations