bumptech / bumptech/glide

onlyRetrieveFromCache fails for local images

Open
#2,110 3 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Java
Stars
35k
Forks
6.2k
Avg merge
1d 11h
Merged PRs (30d)
8

Description

**Glide Version**:4.0.0-RC1
**Integration libraries**:okhttp-integration:4.0.0-RC1
**buildToolsVersion**:25.0.3
**compileSdkVersion**:25
**targetSdkVersion**:25
**Device/Android Version**:x86 emulator API 16 And API 25
**Issue details / Repro steps / Use case background**:
1. I use glide to download some bitmap.
2. Copy these bitmap to my file path.
* On Android 4.1,the path may be like this : data/data/package_name/files/version_xxx/xxx.png
* On Android 7.0,the path may be like this : user/0/package_name/files/version_xxx/xxx.png
3. If these are ready,the nex time when app launch, I use glide to load the local bitmap,it cause GlideException: Failed to load resource.

**Glide load line / `GlideModule` (if any) / list Adapter code (if any)**:
```java
public static final RequestOptions DOWNLOAD_ONLY_OPTIONS =
new RequestOptions().diskCacheStrategy(DiskCacheStrategy.DATA).priority(Priority.HIGH)
.skipMemoryCache(true);
@WorkerThread
private File loadResource(Context context, String url) {
File file = null;
try {
FutureTarget futureTarget = Glide.with(context)
.downloadOnly()
.load(url)
.apply(DOWNLOAD_ONLY_OPTIONS)
.submit();
file = futureTarget.get();
} catch (Exception e) {
LogUtils.e(TAG, e);
}
return file;
}

... copy file if success

public static RequestOptions getOptions() {
if (mBaseRequestOptions == null) {
mBaseRequestOptions = new RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.format(DecodeFormat.PREFER_ARGB_8888);
}
return mBaseRequestOptions.clone();
}

public static RequestOptions getSplashOptions() {
if (mSplashRequestOptions == null) {
mSplashRequestOptions = getOptions()
.diskCacheStrategy(DiskCacheStrategy.NONE)
.onlyRetrieveFromCache(true);
}
return mSplashRequestOptions;
}

Glide.with(this)
.load(launchBackground.getUrl())// This url is my local path
.apply(getSplashOptions())
.into(mDynamicBg);
```

If I use
```java
mDynamicBg.setImageBitmap(BitmapFactory.decodeFile(launchBackground.getUrl()));
```
It works!

**Stack trace / LogCat**:
```java
W/Glide: Load failed for /data/data/package_name/files/splash/26/024ff8a161c32df12fbab8c8e26c668e.png with size [153x153]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
E/Glide: class com.bumptech.glide.load.engine.GlideException: Failed to load resource
```

Contributor guide

Open the contributing guide

Research direction

The issue provides no repository file or test entry point; begin by reproducing the Glide request with a local path, DiskCacheStrategy.NONE, and onlyRetrieveFromCache(true), then inspect the relevant cache and load path. Done means the shown local image loads through Glide under these options on the reported Android versions, with regression coverage if the project’s tests support it.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.