2016-10-11 38 views
0

你好Stackoverflow的男士們! 這是我的第一篇文章,真的是我的改裝2的大問題 我希望有些人幫助解決這個問題。翻譯2解析傳出數據

這是我的接口類:

public interface PicUploadInterface { 
@Multipart 
@POST("user") 
Call<UserModelResponse> uploadMultipleFiles(@Part("Authorization") RequestBody authorization, 
          @Part("description") RequestBody description, 
          @Part MultipartBody.Part filePart); 

和apimanager類:

public class Apimanager { 

public static void upload(String coda, File file) { 
    // create upload service client 
    final String API_BASE_URL = "http://10.0.3.2/web2Demo/public/"; 
    OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); 

    HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); 
    // set your desired log level 
    logging.setLevel(HttpLoggingInterceptor.Level.BODY); 
    httpClient.addInterceptor(logging); 

    Retrofit builder = 
      new Retrofit.Builder() 
        .baseUrl(API_BASE_URL) 
        .addConverterFactory(GsonConverterFactory.create()) 
        .client(httpClient.build()) 
        .build(); 

    PicUploadInterface service = builder.create(PicUploadInterface.class); 
    RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file); 

    MultipartBody.Part filePart = MultipartBody.Part.createFormData("uploaded_file", file.getName(), requestFile); 

    String descriptionString = coda; 
    String AuthString = "Send picture"; 
    RequestBody description = RequestBody.create(MediaType.parse("text/plain"), descriptionString); 
    RequestBody authorization = RequestBody.create(MediaType.parse("text/plain"), AuthString); 

    Call<UserModelResponse> call = service.uploadMultipleFiles(authorization, description, filePart); 
    call.enqueue(new Callback<UserModelResponse>() { 
     @Override 
     public void onResponse(Call<UserModelResponse> call, 
           Response<UserModelResponse> response) { 
      Log.v("Upload", "success"); 
     } 
     @Override 
     public void onFailure(Call<UserModelResponse> call, Throwable t) { 
      Log.e("Upload error:", t.getMessage()); 
     } 
    }); 
} 

,並使用我的代碼是這樣的:

 File file = new File(textViewFile.getText().toString()); // getting this string "/storage/emulated/0/bichooser/1476172212892.jpg" 
     connectivity.com.pack.Apimanager.upload(name, file); 

最後我HttpLoggingInterceptor表明這一點,我不能找到我restApi中是什麼和如何解析它

3月10日至11日:50:12.944 1393年至1681年/ transfer.com.bermou d/pager.tab.component.RegisterFormFragments:onImageChosen: /storage/emulated/0/bichooser/1476172212892.jpg -10- 11 03:50:41.236 1393-2102/transfer.com.bermou D/OkHttp: - > POST http://10.0.3.2/web2Demo/public/user http/1.1 10-11 03:50:41.244 1393-2102/transfer.com.bermou D/OkHttp :Content-Type: multipart/form-data; border = 66e09d68-b88d-4ace-b978-a56e1a6ab66b 10-11 03:50:41.244 1393-2102/transfer.com.bermou D/OkHttp: Content-Length:59914 10-11 03:50:41.244 1393-2102 /transfer.com.bermou W/dalvikvm:VFY:無法找到簽名中引用的類 (Ljava/nio/file/Path;)10-11 03:50:41.244 1393-2102/transfer.com.bermou W/dalvikvm:VFY:無法找到在簽名中引用的類 ([Ljava/nio/file/OpenOption;)10-11 03:50:41.244 1393-2102/transfer.com.bermou I/dalvikvm:找不到 方法java.nio.file.Files.newOutputStream,從方法引用 okio.Okio.sink 10-11 03:50:41.244 1393-2102/transfer.com.bermou W/dalvikvm:VFY:無法解析靜態方法35770 :(Ljava/nio/file/OpenOption;)Ljava/io/OutputStream; 10-11 03:50:41.244 1393-2102/transfer.com.bermou D/dalvikvm:VFY: 在0x000b處替換操作碼0x71 10-11 03:50:41.244 1393-2102/transfer.com.bermou W/dalvikvm:VFY:無法找到在簽名中引用的類 (Ljava/nio/file/Path;)10-11 03:50:41.248 1393-2102/transfer.com.bermou W/dalvikvm:VFY:無法找到類 在簽名中引用([Ljava/nio/file/OpenOption;)10-11 03:50:41.248 1393-2102/transfer.com.bermou I/dalvikvm:找不到 方法java.nio.file.Files。 newInputStream,從方法引用 okio.Okio.source 10-11 03:50:41.248 1393-2102/transfer.com.bermou W/dalvikvm:VFY:無法解析靜態方法35769: Ljava/nio/f ile/Files; .newInputStream (Ljava/nio/file/Path; [Ljava/nio/file/OpenOption;)Ljava/io/InputStream; 10-11 03:50:41.248 1393-2102/transfer.com.bermou D/dalvikvm:VFY: 在0x000b處替換操作碼0x71 10-11 03:50:41.268 1393-2102/transfer.com.bermou D/dalvikvm:GC_FOR_ALLOC已釋放2130K, 30%免費7056K/9952K,暫停4ms,總計4ms 10-11 03:50:41.272 1393-2102/transfer.com.bermou D/OkHttp: JFIF C 10-11 03:50:41.272 1393-2102/transfer.com.bermou D/OkHttp: } !1AQa「q2 #B R $3br 10-11 03:50:41.272 1393-2102/transfer.com。bermou d/OkHttp: &%「()* 456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz
3月10日至11日:50:41 272 1393至2102年/ transfer.com.bermou d/OkHttp: 瓦特1AQaq「2B! #10-11 3Rbr 03:50:41 272 1393至2102年 /transfer.com.bermou d/OkHttp: & 4%$「()* 56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz?XPOJ2yrɆpVBQv0+ \ BS4 三月10日至11日:50:41 272 1393至2102年/ d transfer.com.bermou/OkHttp: rITӍJs)(߻} q l問三月10日至11日:50:41 272 2193至02年 /transfer.com.bermou d/OkHttp: ] \%和ICC#\ 25R㒝H 8ڔ10-11和03:50:41 272 1393年至2102年 /transfer.com.bermou d/OkHttp: /isnVnץ%(fBSzr < FusW END (POST體59914字節)============================== ================================================== ===================================

我找不到什麼是從2.1.0走出去改造我RESTAPI,哪一部分是我的字符串或圖像數據嗎? 我確實改變根據計算器的提示許多團隊和其他的網站,但我的結果幾乎是一樣的! (我的確從即將離任的攔截日誌短的二進制圖像) 如果有人有想法,請分享。由於

+0

什麼[Rü得到響應回調改造? – darwin

+0

的確是我在發佈日期和響應這次大問題狀態並沒有對我很重要。 – CodeSqueezer

回答

0

您是否嘗試過直接在您的服務請求使用:

RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file); 

...

Call<UserModelResponse> call = service.uploadMultipleFiles(authorization, description, requestFile); 

和更新的:

@Multipart 
@POST("user") 
Call<UserModelResponse> uploadMultipleFiles(@Part("Authorization") RequestBody authorization, 
          @Part("description") RequestBody description, 
          @Part("file\"; filename=\"myFilename\" ") RequestBody filePart); 

另一件事,如果你想看到你的RESTAPI查你的電話,你可以使用代理和代理反向看到您的調用和響應。

+0

仍然不是我的問題的解決和okhhtp日誌開始的Content-Type:多/表單數據;邊界= 66e09d68-b88d-4ace-b978-a56e1a6ab66b和dosnt包括授權,描述標籤和在持續()圖像字節代碼! – CodeSqueezer