Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在Android10以上,上传文件失败,原因已找到,请修复 #95

Open
codinglesstech opened this issue Jan 19, 2024 · 0 comments

Comments

@codinglesstech
Copy link

public static String getFilePathFromURI(Context context, Uri contentUri) {
    //copy file and send new file path
    String fileName = getFileName(contentUri);
    if (!TextUtils.isEmpty(fileName)) {
        //File copyFile = new File( Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + fileName);
        /**
         * BugFix: No permission After Android 10 ( Api 29), It will make a upload error 
         * /storage/emulated/0/image-646b1008-1611-4fd9-9758-8cdc15f1021d3788506624350752213.jpg
         * 需要将上传文件的缓存放到私有缓存中,不要随意使用保护目录
         */
        File copyFile = new File( context.getExternalCacheDir().getAbsolutePath() + File.separator + fileName);
        FileUtils.copy(context, contentUri, copyFile);
        return copyFile.getAbsolutePath();
    }
    return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant