-
Notifications
You must be signed in to change notification settings - Fork 984
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
Need help with uploading json and file as multipart/form-data #1108
Comments
The issue is with the way the payload is constructed. According to your Here’s how to fix it in Faraday v1.0. See more about the Multipart Middleware… -payload = {message: JSON.dump(message)}
+payload = { message: Faraday::ParamPart.new(JSON.dump(message), ‘application/json’) } In Faraday v0.1x (confirmed in 0.17.3). Note that this still sends a “file” that's just reading from an in-memory IO object. Hopefully the server doesn’t mind the extra multipart header values. You can see the details in the 3rd request at the bottom of this message. -payload = {message: JSON.dump(message)}
+{ message: Faraday::UploadIO.new(StringIO.new(JSON.dump(message)), 'application/json') } I don’t know what to make of the error message your server replied with though.
I'm hoping that fixing the multipart content type issue will solve it, as I don't see where Let me know if you have any more questions! Showing my workYou can see the working code snippets in multipart.rb · GitHub. Since the RequestBin that the code references only holds the request info temporarily, I’m recording the details below: Request with NO content type in payload:
Request WITH content type (Faraday 1.0)
Request WITH content type (Faraday v0.17.3)
|
Thank you very much for your help, @technoweenie ! You're awesome!! |
Glad to hear it works as expected now! |
Below is what I need to upload
Please note content type that the server receives is
multipart/form-data
my current code looks like below:
However, the response I get from the server is
{"success"=>false, "errorCode"=>nil, "message"=>"Content type 'application/octet-stream' not supported", "data"=>nil}
I tweaked the code little by little and tried again, and searched google for hours but could not find solution.
It would be greatly appreciated if someone can help me with this.
Thank you in advance :D
P.S. this issue seems to be related with #830 (comment) and #769 (comment) , but I cannot find solution.. Please help..
The text was updated successfully, but these errors were encountered: