-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
How to send metadata when using restful api to upload a image? #6771
Comments
You would set it in the See the examples in the docs where different content types are used, such as |
@mtrezza docs not mentioned how to send metadata or tags. |
Did you try to set a request body like this:
That is what happens in the Parse JS SDK. |
@mtrezza Yes, this is the "hack" way I used in my code.
|
Glad to see it works. Adding Would you want to add this to the documentation and open a PR? |
@mtrezza Let me test it with move _ApplicationId from json body to header. And I also want upload file with multipart/form-data instead of base 64. |
I'm closing this as it seems to be resolved. Feel free to comment if you have any questions and we can re-open this issue. Docs issue in parse-community/docs#749 |
One important caveat for this working is one should not add the applicationId in the header, because otherwise the json parsing of the body will be skipped: parse-server/src/middlewares.js Lines 79 to 93 in fe02d3e
|
@evtimDev Do you think the documentation could be improved? |
Hi @mtrezza! Yes, improved documentation for the REST API would be useful, I also noted it in the doc issue you created, just wanted to make sure it's captured and recorded. I stumbled upon this issue as I wanted to send metadata & tags on file upload from the Android SDK (not supported there) so I had to roll-out a REST API solution for the Android. It is a useful feature, as it can simplify bookkeepings and also save on the additional request to associate a file with a object when the association is implemented in cloud code, on file after save, using the metadata/tags. Since this is supported by JS SDK as well as the REST API, it makes sense to roll-out the capability to all platform SDKs. In looking at the server code, it looks like this was some sort of special-case handling? I wonder if a more consistent approach would be for the server to receive the metadata and tags via headers instead - this will save trying to parse and validate the body as a json. I haven't looked at what changes would be needed on the client SDK side to support this in the iOS/Android SDKs. Should I open new issues to investigate these? I'm thinking one issue per client SDK that does not support file upload with metadata/tags yet, plus one issue for server to support receiving these via headers, does that make sense? |
It probably makes more sense to open a feature request in the specific SDK(s) where you have an actual need for your project. For the simple reason that there is currently low feature parity across SDKs - something we are currently looking into. |
OK, I generalized and opened the following feature requests: parse-community/Parse-SDK-Android#1201 It looks like the metadata/tags are sort of meant to be persisted together with the file (I haven't done extensive read up on the metadata/tags and what storage adapters support persisting those and the cases they correctly round-trip back to the client), it is a bit of a different use-case from what I was looking for - I just want some parameters together with the file POST request (probably best via a header). Considering this, I think we should first evaluate these future requests instead of adding documentation to the REST API at this point. I think the comments in this bug are already a de-facto documentation of how to achieve metadata/tags via REST API for parity to the way JS SDK does this. |
curl -X POST
-H "X-Parse-Application-Id: foo"
-H "X-Parse-REST-API-Key: bar"
-H "Content-Type: application/json"
--data-binary '@src/assets/test.png'
http://localhost:1337/parse/files/test.png
How to send metadata with this post request?
Like in JS SDK, we can do this by
The text was updated successfully, but these errors were encountered: