我正在尝试使用Retrofit库上传图像,但无法在此过程中找到任何成功;
这是我的代码:
File photo = new File(picturePath);
TypedFile typedFile = new TypedFile("multipart/form-data", photo);
GroupTravelServer serverObject = Utils.getRetroFitAdapter();
serverObject.uploadImage(Utils.getAuthHeader(getActivity()), "multipart/form-data", tripId,
typedFile, new Callback<ChatMessageModel>() {
@Override
public void success(C
这是我的界面方法:
@Multipart
@POST("/v1/messages")
void uploadImage(@Header(PARAM_AUTHORIZATION) String authorization,
@Header(PARAM_CONTENT_TYPE) String contentType, @Part("tripId") String tripId,
@Part("image") TypedFile image, Callback<ChatMessageModel> callback);
这是传递的路径:
picturePath= /storage/extSdCard/DCIM/Camera/2014-05-19 17.15.43.jpg
我收到500内部服务器错误
使用以下StackTrace:
java.net.ProtocolException: unexpected end of stream
at com.squareup.okhttp.internal.http.HttpConnection$FixedLengthSource.read(HttpConnection.java:416)
at com.squareup.okhttp.internal.okio.RealBufferedSource$1.read(RealBufferedSource.java:168)
at java.io.InputStream.read(InputStream.java:162)
at retrofit.Utils.streamToBytes(Utils.java:43)
at retrofit.Utils.readBodyToBytesIfNecessary(Utils.java:81)
at retrofit.RestAdapter.logAndReplaceResponse(RestAdapter.java:494)
at retrofit.RestAdapter.access$600(RestAdapter.java:114)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:370)
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:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at retrofit.Platform$Android$2$1.run(Platform.java:142)
at java.lang.Thread.run(Thread.java:841)
D / Retrofit:----
请帮忙!
提前致谢。