I’m using PickVisualMediaRequest
to get an Uri
of a selected file:
For example:
content://media/picker/0/com.android.providers.media.photopicker/media/1000008579
ActivityResultLauncher<PickVisualMediaRequest> pickMedia = registerForActivityResult(new PickVisualMedia(), uri -> {
if (uri != null) {
//
uploadToServer(uri);
}
});
pickMedia.launch(new PickVisualMediaRequest.Builder()
.setMediaType(PickVisualMedia.ImageOnly.INSTANCE)
.build());
No I have no idea how now to upload the file.
I have seen many hacks and workarounds, but I suspect that there is certainly a simple method.
I know that I can get InputStream
using ContentProvider
, but it is not enough for me, because I need the name of the file or at least the type of the file to be able to store it correctly on the server (By using OkHttp / MultiPart). So the best I need is File
object. But how do I get a file object from a Uri?