如何在多部分体中给出文件的路径?

  • 本文关键字:文件 路径 多部 android
  • 更新时间 :
  • 英文 :

public void updateImage(){
EventDetail eventDetail = new EventDetail();
SharedPrefManager sfm = SharedPrefManager.getInstance( context );
ProfileDetail pd = sfm.getUser();
int eventID=getIntent().getIntExtra( eventDetail.getEventId(),0);
RequestBody requestBodyuserid = RequestBody.create(MediaType.parse("multipart/form-data"), String.valueOf(pd.getUserId()));
RequestBody requestBodyeventid = RequestBody.create(MediaType.parse("multipart/form-data"), String.valueOf(eventID));
imagepart = null;
File file = new File(move.getPath());
RequestBody requestBodysubFile = RequestBody.create(MediaType.parse("image/*"), file);
imagepart = MultipartBody.Part.createFormData("sub_file",file.getName(),requestBodysubFile);

Api api = RetrofitClient.getApi().create(Api.class);
Call<ApiResponseWhitoutResData> call = api.uplodeFile(requestBodyuserid,requestBodyeventid ,imagepart);
call.enqueue( new Callback<ApiResponseWhitoutResData>() {
@Override
public void onResponse(Call<ApiResponseWhitoutResData> call, Response<ApiResponseWhitoutResData> response) {
if (response.body().getResCode()  ==  1){
Log.d("user", String.valueOf(imagepart));
Log.d("5",response.body().getResMessage());
Log.d("1234","abc");
Log.d("hiral", String.valueOf(requestBodyuserid));
Toast.makeText( PopActivity.this, response.body().getResMessage(), Toast.LENGTH_LONG ).show();
}
else {
Toast.makeText( PopActivity.this, response.body().getResMessage(), Toast.LENGTH_LONG ).show();
}
}
@Override
public void onFailure(Call<ApiResponseWhitoutResData> call, Throwable t) {
Log.d( "fail",""+t.getLocalizedMessage() );
Toast.makeText( PopActivity.this,"Faild" , Toast.LENGTH_LONG ).show();
}
} );
}

在我的日志猫中获取此内容

2020-06-22 18:50:28.384 28916-28949/com.aswdc.archdaily D/OkHttp: --> POST http://www.eatfresh.cc/arch_daily/api/addSubFile
2020-06-22 18:50:28.384 28916-28949/com.aswdc.archdaily D/OkHttp: Content-Type: multipart/form-data; boundary=39e44899-905e-4a76-9580-52ab78cfc42f
2020-06-22 18:50:28.386 28916-28949/com.aswdc.archdaily D/OkHttp: Content-Length: 599
2020-06-22 18:50:28.392 28916-28916/com.aswdc.archdaily D/fail: /document/image:418347 (No such file or directory)
2020-06-22 18:50:28.427 28916-28916/com.aswdc.archdaily I/Choreographer: Skipped 2 frames!  The application may be doing too much work on its main thread.
2020-06-22 18:50:28.522 28916-28916/com.aswdc.archdaily I/Choreographer: Skipped 4 frames!  The application may be doing too much work on its main thread.
2020-06-22 18:50:28.552 28916-28916/com.aswdc.archdaily I/Choreographer: Skipped 1 frames!  The application may be doing too much work on its main thread.

如果您在文件选择时打开文档提供程序,则您返回的 Uri 因文件源而异。[API 级别 19 及以上] 看 通过改造上传文件时出现错误(没有此类文件或目录(

最新更新