在我的应用程序中,我有文件上传概念。我必须上传图片或视频或音频。什么时候我上传文件,它进入失败方法。在选择任何类型的文件时未上传到服务器。在Android V5.0中它需要图像一些视频文件。更多时候它会失败。
ApiConfig service = ServiceGenerator.createService(ApiConfig.class);
File file = FileUtils.getFile(this, fileUri);
Log.d("File", String.valueOf(file));
uploadfile.setText(String.valueOf(file));
RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file);
MultipartBody.Part body = MultipartBody.Part.createFormData("picture", file.getName(), requestFile);
String descriptionString = "hello, this is description speaking";
RequestBody description = RequestBody.create(MediaType.parse("multipart/form-data"), descriptionString);
Call<ResponseBody> call = service.upload(body);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call,
Response<ResponseBody> response) {
progressDialog.dismiss();
String Image_Url=null;
try {
Image_Url=response.body().string();
} catch (IOException e) {
e.printStackTrace();
}
Log.d("serverResponse.getData() ", Image_Url);
Validations.MyAlertBox(AddNewFile.this, "File Successfully Uploaded");
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
progressDialog.dismiss();
Validations.MyAlertBox(AddNewFile.this, "File not Uploaded");
}
});