You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Maybe is something i'm doing while forming the request but just wanted to share my experience implementing retrofit with our api.
First of all i'm using the source project from here last updated yesterday.
This is the api interface call:
How i created the RequestBody for the file and texts in first instance:
RequestBody file = RequestBody.create(mimeType, file);
RequestBody text = RequestBody.create(null, "text"); //For each text part
Doing it this way is our server response was "Missing boundary in multipart/form-data POST data in Unknown on line 0". Firstly i thought that adding it to Headers annotation in the interface call would solve this but our server kept giving the same response. Finally adding these lines just before the return to RequestFactoryParser class(Line 194) solved the boundary issue
Once i had the boundary in my request the next problem was the file part, our Api is coded in PHP and uses the tmp_name from $_FILE[] but creating the RequestBody to upload a file with the rest of the data wasn't adding the filename var to the Content-Type header of this request.
I didn't find a way to check mime-type of Part in parseParameters(Retrofit retrofit) method inside RequestFactoryParser class so inside RequestBuilderAction.Part, RequestBuilderAction (Line 211) i check if mime type is an image, the only files we accept so far, and update headers accordingly if it is.
I just added this,
So my question is, i'm i missing something? This is the first time i use retrofit and okhttp and probably, what i want to achieve, send an image and other plain text data in the same request, has to be done other ways but i haven't found any. I also tried to create each RequestBody with MultipartBuilder().build() and other things, like creating just a single RequestBody for all the data, with no luck. The only thing that has worked for me so far is this one.
The text was updated successfully, but these errors were encountered:
This sounds like #1140, where the filename isn't being added which is breaking the backend. If you can demonstrate otherwise (like with a failing test, ideally) then I'll re-open. But once #1140 is fixed this should just start working.
Maybe is something i'm doing while forming the request but just wanted to share my experience implementing retrofit with our api.
First of all i'm using the source project from here last updated yesterday.
This is the api interface call:
How i created the RequestBody for the file and texts in first instance:
Doing it this way is our server response was "Missing boundary in multipart/form-data POST data in Unknown on line 0". Firstly i thought that adding it to Headers annotation in the interface call would solve this but our server kept giving the same response. Finally adding these lines just before the return to RequestFactoryParser class(Line 194) solved the boundary issue
Once i had the boundary in my request the next problem was the file part, our Api is coded in PHP and uses the tmp_name from $_FILE[] but creating the RequestBody to upload a file with the rest of the data wasn't adding the filename var to the Content-Type header of this request.
I didn't find a way to check mime-type of Part in parseParameters(Retrofit retrofit) method inside RequestFactoryParser class so inside RequestBuilderAction.Part, RequestBuilderAction (Line 211) i check if mime type is an image, the only files we accept so far, and update headers accordingly if it is.
I just added this,
and finally got it working.
So my question is, i'm i missing something? This is the first time i use retrofit and okhttp and probably, what i want to achieve, send an image and other plain text data in the same request, has to be done other ways but i haven't found any. I also tried to create each RequestBody with MultipartBuilder().build() and other things, like creating just a single RequestBody for all the data, with no luck. The only thing that has worked for me so far is this one.
The text was updated successfully, but these errors were encountered: