I'm trying to upload the image to imageview via Uri it doesn't work.
java.io.FileNotFoundException: /file:/data/user/0/com.maksu.aquarium/cache/cropped6681458112782885202.jpg (No such file or directory)
I get the above error. When I check, I see the picture exists.
This is how I upload the photo:
Uri profileUri = Uri.fromFile(new File("file:///data/user/0/com.maksu.aquarium/cache/cropped6681458112782885202.jpg"));
Glide.with(this).load(profileUri).into(akvaryumDialogResim);
First, never hardcode paths . For the purposes of this answer, I will stick with your hardcoded value, but you really need a better way of handling your files. For example, your hard-coded path will be wrong for lots of users.
Second, file:///data/user/0/com.maksu.aquarium/cache/cropped6681458112782885202.jpg
is not a filesystem path. It is a Uri
. Android is based on Linux, and its filesystem paths start with /
. file://
is a Uri
scheme, much like how https://
is a Uri
scheme used in the URL for this Web page.
So, either use:
Uri profileUri = Uri.parse("file:///data/user/0/com.maksu.aquarium/cache/cropped6681458112782885202.jpg");
or use:
Uri profileUri = Uri.fromFile(new File("/data/user/0/com.maksu.aquarium/cache/cropped6681458112782885202.jpg"));
To get access to file in the cache folder, you can use Context.getCacheDir()
method and not hardcode full path. So, try:
Uri profileUri = Uri.fromFile(new File(geCacheDir(), "cropped6681458112782885202.jpg"));
Glide.with(this).load(profileUri).into(akvaryumDialogResim);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.