Closed Pangeran29 closed 11 months ago
Hi, show how you send a request, e.g. through a rest client such as postman or insomnia
@dmitriy-nz yes, i use swagger to send the request. this is how it looks in swagger
and this is the curl (banner is the array of image that i send)
@Pangeran29 Please note the readme, the section "Validation of file arrays" https://github.com/dmitriy-nz/nestjs-form-data#validate-the-array-of-file The key must be in the format "key[]". I don't quite understand what's wrong with your array output in the log, please make it readable
I have the same problem there. The format of array is like: [...data from file 1, ' ': [...data from file 2, ' ': [ ...data from file 3 ] ] ]
Any progress on this issue?
Here is a very dirty workaround:
@Transform((obj) => { const arr = []; let field = obj.value; while (field) { const temp = field['']; delete field['']; arr.push(Object.assign(new FileSystemStoredFile(), field)); field = temp; } return arr; })
@nikola418 Please read doc:
IsFiles
decorator to validate an array of files.
https://github.com/dmitriy-nz/nestjs-form-data#isfilesappend-field
library used to parse field keys and build the multi level object is not working as it should.
I don't have a lot of time right now, I'll get to it soon.Here is a very dirty workaround:
@Transform((obj) => { const arr = []; let field = obj.value; while (field) { const temp = field['']; delete field['']; arr.push(Object.assign(new FileSystemStoredFile(), field)); field = temp; } return arr; })
This was the only way to make it work for me. Thanks.
I use this library in many projects, including for loading arrays of files, if you follow the readme.
Anyway, I fixed a bug in the node-append-field
library in version 1.9.1 and now everything should work fine without explicitly specifying the array sign in the file key.
Open the issue again if the problem occurred after updating to version 1.9.1.
Here is a very dirty workaround:
@Transform((obj) => { const arr = []; let field = obj.value; while (field) { const temp = field['']; delete field['']; arr.push(Object.assign(new FileSystemStoredFile(), field)); field = temp; } return arr; })
i think this can be shortened to this, which also worked for me:
@Transform(({ obj }) => obj.files)
This issue was completely fixed in the v1.9.9, please reopen issue if you still have that problem.
hello.. i try to upload many image using nestjs-form-data but the array response is not valid array of objects, and i can't iterate it this is my dto configuration:
@ApiProperty({ type: 'array', items: { type: 'string', format: 'binary', }, required: true, }) @IsNotEmpty() @IsFile({ each: true }) @MaxFileSize(2000000, { each: true }) @HasMimeType(['image/jpeg', 'image/png', 'image/jpg'], { each: true }) banner: FileSystemStoredFile[];
and when i try console.log it returning invalid array format
[ originalName: 'picture_991_posterproduk-masarasara-pants-1-sz.png', encoding: '7bit', busBoyMimeType: 'image/png', path: 'D:\\nguli\\maxsol\\goon\\public\\banner\\picture_991_posterproduk-masarasara-pants-1-sz-87b8a7.png', size: 114098, fileType: { ext: 'png', mime: 'image/png' }, '': FileSystemStoredFile { originalName: 'Screenshot 2022-09-07 160046.png', encoding: '7bit', busBoyMimeType: 'image/png', path: 'D:\\nguli\\maxsol\\goon\\public\\banner\\Screenshot 2022-09-07 160046-7b8a72.png', size: 284564, fileType: { ext: 'png', mime: 'image/png' }, '': FileSystemStoredFile { originalName: 'Screenshot 2022-09-07 160046.png', encoding: '7bit', busBoyMimeType: 'image/png', path: 'D:\\nguli\\maxsol\\goon\\public\\banner\\Screenshot 2022-09-07 160046-b8a721.png', size: 284564, fileType: [Object] } } ]
is this the right response when uploading array of image in nestjs-form-data??