Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Does the API support multipart/form-data? #30

Closed
rijkvanzanten opened this issue Mar 27, 2018 · 6 comments
Closed

Does the API support multipart/form-data? #30

rijkvanzanten opened this issue Mar 27, 2018 · 6 comments
Labels
question Further information is requested tests Needs test case

Comments

@rijkvanzanten
Copy link
Member

For uploading images, next to sending the image's data string through a regular POST request?

@rijkvanzanten rijkvanzanten added the question Further information is requested label Mar 27, 2018
@wellingguzman
Copy link
Contributor

It doesn't support multipart/form-data, (it will ignore the upload data).

@rijkvanzanten
Copy link
Member Author

rijkvanzanten commented Mar 27, 2018

Question 2:

Why not?

Q 3:

Can the API support multipart/form-data?

@wellingguzman
Copy link
Contributor

wellingguzman commented Mar 27, 2018

Why not?

No reason at all, we haven't implemented yet.

Can the API support multipart/form-data?

Yes it can support it. Probably the only drawback is that we can't sent user-defined information about this file, such as file title, description.

@rijkvanzanten
Copy link
Member Author

the only drawback is that we can't sent user-defined information about this file, such as file title, description.

If we include fields in the same form with the name matching the database column, it should be doable right?

@wellingguzman
Copy link
Contributor

The file data uploaded will replace the field containing the user-defined (if any) title, description etc.

Example:

Currently we can do this:

{
  "title": "new article",
  "header_image": {
    "title": "new article header image",
    "description": "a happy team",
    "data": "<base-64-data>"
  }
}

We send user-specific information such as title and description.

On the other hand when we use multipart the data for header_image that field information becomes only the file data: rough example below:

POST /_/items/articles HTTP/1.1
Host: directus-api.local
Content-Type: multipart/form-data; boundary=----Boundary

----Boundary
Content-Disposition: form-data; name="title"

new article
----Boundary
Content-Disposition: form-data; name="header_image"; filename="header_image.jpg"
Content-Type: image/jpeg

<ImageContent>
----Boundary--

The header section has the binary content of the header_image.jpg.

We can research if there's a possible way to send this information through multipart or we can create a workaround.

@rijkvanzanten
Copy link
Member Author

Ahh, yeah we lose the ability to send nested values, that's true. But it would still be useful for asynchronous uploads to /files directly.

Usecase: uploading files to insert into a WYSIWYG editor

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested tests Needs test case
Projects
None yet
Development

No branches or pull requests

2 participants