You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched existing issues to ensure the issue has not already been raised
Issue
Hello there.
I would like to add testing to my endpoint which uses fastify/multipart to accept a file upload and then writes it to the filesystem.
In the testing directory of this repository I saw that popular form-data library is used, however, I think this can also be achieved without it?
What I have come up with, but for some reason does not work:
const__filename=fileURLToPath(import.meta.url)const__dirname=dirname(__filename)constfilePath=join(__dirname,'../example.jpg')describe('POST /asset',()=>{it('should return 201 when the payload is valid',async()=>{constrawData=readFileSync(filePath,'binary')constbody=newFormData()constblob=newBlob([rawData])body.set('file',blob,'example.jpg')constres=awaitapp.inject({method: 'POST',url: '/asset',payload: {file: body.get('file')}})assert.deepStrictEqual(res.statusCode,201)})})
However, this gives me the following error:
{"statusCode":400,"code":"FST_ERR_VALIDATION","error":"Bad Request","message":"body/file should be a file"}
This is my route definition (I do not think this is relevant, but maybe it could be):
Prerequisites
Issue
Hello there.
I would like to add testing to my endpoint which uses
fastify/multipart
to accept a file upload and then writes it to the filesystem.In the testing directory of this repository I saw that popular
form-data
library is used, however, I think this can also be achieved without it?What I have come up with, but for some reason does not work:
However, this gives me the following error:
This is my route definition (I do not think this is relevant, but maybe it could be):
Is there any way to make this testing work?
Thank you very much in advance.
The text was updated successfully, but these errors were encountered: