android-upload-service icon indicating copy to clipboard operation
android-upload-service copied to clipboard

Add contentType to addParameter

Open vallemar opened this issue 1 year ago • 3 comments

Describe the solution you'd like There are times when we want to declare the contentType of a parameter, as in this case: https://stackoverflow.com/a/60968768/6015400

Currently there is no way to declare the contentType of the parameter in question, it can only be done for the file

Are you willing to implement it and maintain it?

  • [ ] Yes
  • [ ] Can implement it with a Pull Request, but not maintain it
  • [X] No

vallemar avatar Apr 09 '24 23:04 vallemar

Hi @vallemar from a protocol standpoint, key-values parameters passed in multipart form data are always strings. If the server requires the values to be something specific, it's weak to depend on the client. So, for the example you mentioned, on the server side it's possible to simply check if the string value is a json and return a 4xx validation error to the client if it's not. The server should do that validation in any case, whether you specify content type or not from the client.

gotev avatar Apr 10 '24 07:04 gotev

Hi @gotev , yes, I understand the point, but always sending strings will be the default value, not always, frameworks such as axios, spring boot or the postman tool allow it so I understand that it will be an additional configuration within the protocol (I am not an expert). Thank you very much for your prompt response

vallemar avatar Apr 10 '24 10:04 vallemar

Sure, many tools allows it, but it's still an edge case and may cause problems with some servers, as it's not common standard. The library aims at providing the best compatibility with all kind of servers. For example, OkHttp doesn't allow this even in latest 5.x versions, as it follows strictly RFC 2387.

My 2 cents here if you're in an edge case like this: why a server would want to force the clients to do that? Specifying content types explicitly like that deviates from the standard, it increases payload size and does not add anything from a validation standpoint, as the server still gets form data params as raw url encoded input strings when reading from the stream.

gotev avatar Apr 10 '24 11:04 gotev

Closing this issue. Currently this is not going to be implemented in the library.

gotev avatar Jul 10 '24 13:07 gotev