改造中的图像上传:内部服务器错误

时间:2016-03-09 13:19:04

标签: android image file-upload service retrofit2

我正在尝试将文件上传到服务器,但responseObject.isSuccess()正在返回false。以下是服务和调用代码。请告诉我代码有什么问题。

要发布的API:

@Multipart
@POST("/operation/Api/fileSync")
Call<SyncResponse> uploadImage(
    @QueryMap Map<String, String> params, 
    @Part("myfile\"; filename=\"image.jpg\" ") RequestBody image
);

和调用服务的代码:

public void uploadImage() {

    Retrofit retrofit = RetrofitClientManager
        .getInstance(getApplicationContext())
        .getRetrofitBuilder();
    SyncAPI syncAPI = retrofit.create(SyncAPI.class);

    MediaType MEDIA_TYPE_PNG = MediaType.parse("image/jpeg");
    File file = new File(KEY_NAME);
    RequestBody image = RequestBody.create(MEDIA_TYPE_PNG, file);

    Map<String, String> paramMap = new HashMap<String, String>();
    paramMap.put("AUTHCHECKSUM", authchecksum);
    paramMap.put("name",file.getName());
    paramMap.put("type","image/jpeg");


    Call<SyncResponse> call = syncAPI.uploadImage(paramMap, image);

    try {
        RetrofitClientManager
            .getInstance(getApplicationContext())
            .execute(1, call, this);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }

1 个答案:

答案 0 :(得分:0)

请尝试使用private void WorkingThreadFunction(object args) {}

TypedFile

然后,在import retrofit.mime.TypedFile; @Multipart @POST("/operation/Api/fileSync") Call<SyncResponse> uploadImage( @QueryMap Map<String, String> params, @Part("image") TypedFile image ) 中尝试以下内容:

uploadImage()