【发布时间】:2023-01-21 20:16:53
【问题描述】:
我正在尝试删除 MANAGE_EXTERNAL_STORAGE,但在删除此权限后我无法从给定路径上传 Multipart。
我正在使用这行代码来获取 pdf 文件,
`Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("application/pdf");
resultLauncher.launch(intent);`
我得到了这样的路径
/storage/emulated/0/Download/offer.pdf
获得此路径后,我使用以下代码将其转换为 Multipart 并将其上传到服务器,
`File file = new File(path);
MultipartBody.Part filePart = MultipartBody.Part.createFormData("file", file.getName(), RequestBody.create(file, MediaType.parse("application/pdf")));`
在将其上传到服务器时出现错误:
java.io.FileNotFoundException: /storage/emulated/0/Documents/mSchooling/offer.pdf: open failed: EACCES (Permission denied).
一件事是我已经给出了 read_external_storage 和 write_external_storage。
请帮我解决这个问题。
我试过这段代码来获取文件,
ntent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("application/pdf"); resultLauncher.launch(intent);
并尝试使用以下代码将其转换为 Multipart,
File file = new File(path); MultipartBody.Part filePart = MultipartBody.Part.createFormData("file", file.getName(), RequestBody.create(file, MediaType.parse("application/pdf")));
【问题讨论】: