Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow creating model and saving file in one request #45

Open
abzainuddin opened this issue Feb 7, 2017 · 7 comments
Open

Allow creating model and saving file in one request #45

abzainuddin opened this issue Feb 7, 2017 · 7 comments

Comments

@abzainuddin
Copy link
Contributor

Now you have to:

  1. save the model
  2. save the file

Maybe some special sauce for multiput?

@stefanmajoor
Copy link
Collaborator

Maybe integrate the ImageView from HN directly too?

@irfinnew
Copy link

@abzainuddin But file uploads require a multipart/form-data body, rather than a plain json body.

I can see two possible ways to achieve this:

  • Post the image base64-encoded as part of the json
  • Post both the image and the json body in a multipart/form-data body

@abzainuddin
Copy link
Contributor Author

POSTing base64 might be slow, especially for bigger files / mobile devices. I would prefer option 2.

@irfinnew
Copy link

Would option 2 be reasonable to implement in the FE?

@SpaceK33z
Copy link
Contributor

@mmoreaux yes (Burhan asked me to approve this). So in the form data there would be a file field and a data field, where the file field contains the blob and the data field stringified JSON, right?

@irfinnew
Copy link

@SpaceK33z Something like that, yes. Would that be OK?

The details will probably differ a bit, e.g. to accommodate multiple images on a single entity, or on a single multiput. But that mainly involves having unique names for the file parts, and attaching them to the proper file field.

Maybe like this:

POST /api/foo/

form-data data: text

{
	"name": "Foo",
	"barness:" 5,
	"cover_image": "form:cover_image1",
	"other_image": "form:c440aa6"
}

form-data file_cover_image1: file

form-data file_c440aa6: file

(having the form: prefix allows us to add base64: and other prefixes in the future)

@SpaceK33z
Copy link
Contributor

Yes, that would be okay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants