java filebody出错_android – 处理请求时捕获的java.io.FileNotFoundException:/document/raw:/storage/emulated/0/Do...

我想使用multipart请求将pdf发送到我的服务器.我能够正确选择文件并得到它的名字但是当我发送这个pdf时,我发送以下路径/document/raw:/storage/emulated/0/Download/kitchenapp.pdf.路径是正确的,文件在那里,但我有这个例外. I / DefaultRequestDirector:处理请求时捕获的I / O异常(

java.io.FileNotFoundException):/document/raw:/storage/emulated/0/Download/kitchenapp.pdf(没有这样的文件或目录)

到目前为止我做了什么..通过这个获取pdf

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);

intent.setType("application/pdf");

intent.addCategory(Intent.CATEGORY_OPENABLE);

try {

startActivityForResult(

Intent.createChooser(intent, "Select a File to Upload"),

1);

} catch (android.content.ActivityNotFoundException ex) {

Toast.makeText(getActivity(), "Please install a File Manager.",

Toast.LENGTH_SHORT).show();

}

通过此获取onActivity结果

@Override

public void onActivityResult(int requestCode, int resultCode, Intent data) {

// TODO Auto-generated method stub

super.onActivityResult(requestCode, resultCode, data);

if (requestCode == 1 && resultCode == RESULT_OK && data != null && data.getData() != null) {

Uri selectedFileURI = data.getData();

file = new File(selectedFileURI.getPath().toString());

Log.d("", "File : " + file.getName());

String uploadedFileName = file.getName().toString();

System.out.println("upload file name "+uploadedFileName);

System.out.println("my location "+file);

}

}

通过多部分请求发送此文件

if (file != null ) {

entity.addPart("file", new FileBody(file));

}

// totalSize = entity.getContentLength();

httppost.setEntity(entity);

// Making server call

HttpResponse response = httpclient.execute(httppost);

HttpEntity r_entity = response.getEntity();

任何帮助将是欣赏..

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值