Hi,
I'm wondering if it is possible to simulate a file upload. For example, in my ReactJS, I use FormData to send a file to Adonis, which uses request.file(). An example of an output of a file would be the following:
[File(234234)]
0: File(234234)
lastModified: "...",
lastModifiedDate: "...",
name: "filename.png",
preview: "..."
...
...
Then, in my test file, I attempted to send a JSON in this format, but it's no good.
const request = await client.post("http://127.0.0.1:4000/api/v1/invoices/1/additional-files")
.send({
id: 4,
invoice_id: 1,
File: {
name: "a_new_file_uploaded.png"
},
description: "Lorem ipsum dolor sit amet"
})
.end();
Is there another way to simulate a file?
Uploading files is not about sending the file data in JSON format. It's about the data is sent in multipart.
Read documentation here https://adonisjs.com/docs/4.1/api-tests#_multipart_requests
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Uploading files is not about sending the file data in JSON format. It's about the data is sent in
multipart.Read documentation here https://adonisjs.com/docs/4.1/api-tests#_multipart_requests