Android文件选择器&;上载获取文件未找到错误

Android文件选择器&;上载获取文件未找到错误,android,Android,我可以选择文件,选择的pdf文件的uri为content://somefile但当我使用unirest发送文件时,getting error file not found异常下面是我的代码 //file chooser File file; Intent chooseFile = new Intent(Intent.ACTION_GET_CONTENT); chooseFile.setType("*/*"); chooseFile.addCategory(Inten

我可以选择文件,选择的pdf文件的uri为content://somefile但当我使用unirest发送文件时,getting error file not found异常下面是我的代码

 //file chooser
 File file;
 Intent chooseFile = new Intent(Intent.ACTION_GET_CONTENT);
 chooseFile.setType("*/*");
 chooseFile.addCategory(Intent.CATEGORY_OPENABLE);
 startActivityForResult(Intent.createChooser(chooseFile, "Select a File to Upload"),1);
HttpResponse response=Unirest.post(“http://url/")
.field(“文件”,文件)

您必须使用典型的方法,因此请使用改装,以节省大量时间

文件上载示例-

对于网络,您还必须访问官方改装网站


99%的人建议对网络进行改造以节省大量时间

file=new file(data.getData().getPath())
。getPath()不提供文件系统路径,因此不能使用file类访问uri后面的文件。查看data.getData().toString()和data.getData().getPath()的值。不要乱搞文件类。您可以使用uri data.getData()本身来上载文件。显然,在调用上载代码之前,您没有使用file.exist()。我正在获取此文件内容:/com.android.providers.media.documents/document/document%3a32这是一个很好的内容方案。已使用uri.toString()删除。在尝试上载之前,请在您的代码中添加file.exists()。Please report.file应该存在,因为我可以选择pdf文件我可以提出请求,但是新文件(data.getData().getPath())//我得到了content://somefile 找不到该文件,我可以使用lib file chooser“”并且文件已上载,这是库无法选择pdf文件
data.getData().getPath()的缺点)//我来了content://somefile 
没有。一点也不。getPath()从不以内容开头://。进一步:与从该文件选择器获得的路径进行比较。
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case 1:
                if (resultCode == -1) {
                    file = new File(data.getData().getPath());
                    
                }

                break;
        }
    }
HttpResponse<String> response = Unirest.post("http://url/")
                            .field("file", file)