I am new to android retrofit and need to upload image file using multipart request format. I was able to upload successfully using iphone multipart request. However, had trouble with android retrofit. I use https and token bearer authorization.
@Multipart
@POST("/Api/ApiSales/UploadImages")
void uploadImage(@Part("File") TypedFile file,
Callback<Response> callback);
RestAdapter.Builder builder = new RestAdapter.Builder().setEndpoint(appController.getInstance().getURL());
builder.setRequestInterceptor(new RequestInterceptor() {
@Override
public void intercept(RequestFacade request) {
request.addHeader("Authorization", appController.getInstance().getAuthTokenString());
}
});
builder.setLogLevel(RestAdapter.LogLevel.FULL);
RestAdapter restAdapter = builder.build();
RetrofitService service = restAdapter.create(RetrofitService.class);
service.uploadImage(new TypedFile("image/png",toFile), new Callback<retrofit.client.Response>() {
@Override
public void success(retrofit.client.Response response, retrofit.client.Response response2) {
Log.i(TAG, response.toString());
}
@Override
public void failure(RetrofitError error) {
Log.e(TAG, error.toString());
}
});
I got following error:
retrofit.RetrofitError: Write error: ssl=0x5ef8ad40: I/O error during system call, Connection reset by peer
I set up server for http request, still got error:
retrofit.RetrofitError: sendto failed: ECONNRESET (Connection reset by peer)