Core: Test a file upload with Vow

Created on 27 Apr 2018  路  2Comments  路  Source: adonisjs/core

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?

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

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GianCastle picture GianCastle  路  3Comments

aligoren picture aligoren  路  4Comments

themodernpk picture themodernpk  路  3Comments

milosdakic picture milosdakic  路  3Comments

umaams picture umaams  路  3Comments