I have tried successfully POSTwith Multipart over the past few days with varying degrees of success. At some point, I got it to work, but eventually changed the REST libraries due to problems GET(which I will talk about later if this comes up with Retrofit). I'm trying POSTa right now MultipartTypedOutput. This is how I create it (this is a mixture of File(s) and Strings / Booleans.
I add Filemine to mine Map<String, Object>as follows:
Uri uri = data.getData();
parameterPairsMap.put(fileName, new File(URI.create(uri.toString())));
Then I pass this to another class that processes it like this:
MultipartTypedOutput multipartTypedOutput = new MultipartTypedOutput();
for(Map.Entry<String, Object> entry : pairs.entrySet()){
if(entry.getValue() instanceof File){
multipartTypedOutput.addPart(entry.getKey(), new TypedFile("*/*", (File)entry.getValue()));
}
else{
multipartTypedOutput.addPart(entry.getKey(), new TypedString(entry.getValue().toString()));
}
}
restAdapter.create(RetrofitInterface.class).buildWithParameters(buildName, multipartTypedOutput, callbacks);
What pushes me, I can’t figure out how to create a Retrofit interface for it. I tried both of them and they give the same results, which makes me want to believe that this is a problem with File...
@POST("/job/{buildName}/buildWithParameters")
void buildWithParameters(@Path("buildName") String buildName, @Body MultipartTypedOutput typedOutput, Callback<String> callbacks);
@Multipart
@POST("/job/{buildName}/buildWithParameters")
void buildWithParameters(@Path("buildName") String buildName, @Part("") MultipartTypedOutput typedOutput, Callback<String> callbacks);
W/System.err﹕ retrofit.RetrofitError: java.io.IOException: unexpected end of stream
W/System.err﹕ at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:421)
W/System.err﹕ at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:264)
W/System.err﹕ at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:315)
W/System.err﹕ at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
W/System.err﹕ at retrofit.Platform$Android$2$1.run(Platform.java:142)
W/System.err﹕ at java.lang.Thread.run(Thread.java:841)
W/System.err﹕ Caused by: java.io.IOException: unexpected end of stream
W/System.err﹕ at libcore.net.http.FixedLengthOutputStream.close(FixedLengthOutputStream.java:58)
W/System.err﹕ at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:818)
W/System.err﹕ at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:283)
W/System.err﹕ at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:497)
W/System.err﹕ at retrofit.client.UrlConnectionClient.readResponse(UrlConnectionClient.java:71)
W/System.err﹕ at retrofit.client.UrlConnectionClient.execute(UrlConnectionClient.java:38)
W/System.err﹕ at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:358)
W/System.err﹕ ... 7 more
@Part, . , POST Jenkins, - , .
EDIT: , , . , . , , . :
TypedString . ( entry.getClass() entry.getValue()), .
TypedString @Query , unexpected end of stream. , ?
- . Typed - (TypedAsciiString), US-ASCII. MultipartTypedOutput, (, S/O, , , , ). Multipart8BitTypedOutput, . , .
, . . ( ) . MultipartTypedOutput, . , . ?
D/Retrofit﹕ ---> HTTP POST /*edited*/
D/Retrofit﹕ Authorization: Basic /*edited*/
D/Retrofit﹕ Content-Type: multipart/form-data; boundary=5f8e6431-ed42-4d8b-95ce-d749f1797f04
D/Retrofit﹕ Content-Length: 1090
D/Retrofit﹕ --5f8e6431-ed42-4d8b-95ce-d749f1797f04
Content-Disposition: form-data; name="branch"
Content-Type: text/plain; charset=UTF-8
Content-Length: 18
Content-Transfer-Encoding: binary
testingOneTwoTHree
--5f8e6431-ed42-4d8b-95ce-d749f1797f04
Content-Disposition: form-data; name="one.properties"; filename="local.properties"
Content-Type: */*
Content-Length: 449
Content-Transfer-Encoding: binary
sdk.dir=/Users/gimmiepepsi/Downloads/android-sdk-macosx
--5f8e6431-ed42-4d8b-95ce-d749f1797f04
Content-Disposition: form-data; name="isBoolean"
Content-Type: text/plain; charset=UTF-8
Content-Length: 4
Content-Transfer-Encoding: binary
true
--5f8e6431-ed42-4d8b-95ce-d749f1797f04--
D/Retrofit﹕ ---> END HTTP (1090-byte body)
D/Retrofit﹕ ---- ERROR /* edited */
D/Retrofit﹕ java.io.IOException: unexpected end of stream
at libcore.net.http.FixedLengthOutputStream.close(FixedLengthOutputStream.java:58)
at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:818)
at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:283)
at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:497)
at retrofit.client.UrlConnectionClient.readResponse(UrlConnectionClient.java:71)
at retrofit.client.UrlConnectionClient.execute(UrlConnectionClient.java:38)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:358)
at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:264)
at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:315)
at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at retrofit.Platform$Android$2$1.run(Platform.java:142)
at java.lang.Thread.run(Thread.java:841)
D/Retrofit﹕ ---- END ERROR
W/System.err﹕ retrofit.RetrofitError: java.io.IOException: unexpected end of stream
W/System.err﹕ at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:421)
W/System.err﹕ at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:264)
W/System.err﹕ at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:315)
W/System.err﹕ at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
W/System.err﹕ at retrofit.Platform$Android$2$1.run(Platform.java:142)
W/System.err﹕ at java.lang.Thread.run(Thread.java:841)
W/System.err﹕ Caused by: java.io.IOException: unexpected end of stream
W/System.err﹕ at libcore.net.http.FixedLengthOutputStream.close(FixedLengthOutputStream.java:58)
W/System.err﹕ at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:818)
W/System.err﹕ at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:283)
W/System.err﹕ at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:497)
W/System.err﹕ at retrofit.client.UrlConnectionClient.readResponse(UrlConnectionClient.java:71)
W/System.err﹕ at retrofit.client.UrlConnectionClient.execute(UrlConnectionClient.java:38)
W/System.err﹕ at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:358)
W/System.err﹕ ... 7 more