-
Notifications
You must be signed in to change notification settings - Fork 981
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
Issue with multipart/form data request with json body #769
Issue with multipart/form data request with json body #769
Comments
Hi @ff-sushild, I believe I've identified the issue in this line. The Main reason for this is that mixing JSON and multipart is not really RESTful, so if you don't have the possibility to change the server implementation, a PR to fix this is more then welcome However if you CAN change the server, you have other 2 options and I would strongly suggest to go for one of these:
Let me know what do you end up doing |
Thanks @iMacTia, this is really very helpful to find the RCA and the solution. Will let you know where I end up with. Most probably will have to patch multipart for now and fixing the backend implementation for long term. |
@ff-sushild sounds good! Glad I could help 👍 |
Hello, would you take a PR implementing the patch suggested here ? https://stackoverflow.com/questions/48679598/faraday-multipart-request-with-json-file-data?rq=1 class Faraday::Request::Multipart
def create_multipart(env, params)
boundary = env.request.boundary
parts = process_params(params) do |key, value|
if (JSON.parse(value) rescue false)
Faraday::Parts::Part.new(boundary, key, value, 'Content-Type' => 'application/json')
else
Faraday::Parts::Part.new(boundary, key, value)
end
end
parts << Faraday::Parts::EpiloguePart.new(boundary)
body = Faraday::CompositeReadIO.new(parts)
env.request_headers[Faraday::Env::ContentLength] = body.length.to_s
return body
end
end |
Basic Info
Issue description
When trying to POST multipart data (file & json), remote server is not recognizing json data parameter and failing with validation error as it is required parameter.
Does anyone see any obvious mistake here?
The text was updated successfully, but these errors were encountered: