Any way to get blob of image
Closed this issue · 7 comments
Hi, i have a question, is any way to get blob of image, i need to handle source image with canvas after fetch
Is possible implement on CacheManager.prefetch
or some way? For example:
CacheManager.prefetch(url).then((blob) => {})
Thank you.
Hi @youniaogu sure, we'll add it.
@youniaogu are you using typescript or javascript in your project?
If you're using typescript, can you add this at line ~166 on CacheManager.ts
and let me know if it's what you need:
static async prefetchBlob(
source: string,
options?: DownloadOptions
): Promise<any> {
const path = await CacheManager.get(source, options).getPath();
const blob = await FileSystem.readFile(path, "base64");
return blob;
}
Call it with
CacheManager.prefetchBlob(YOUR IMAGE URL).then((response) =>
console.log(response)
);
@youniaogu are you using typescript or javascript in your project?
If you're using typescript, can you add this at line ~166 on
CacheManager.ts
and let me know if it's what you need:static async prefetchBlob( source: string, options?: DownloadOptions ): Promise<string> { if (typeof source === "string") { const path = await CacheManager.get(source, options).getPath(); const blob = await FileSystem.readFile(path, "base64"); return blob; } }Call it with
CacheManager.prefetchBlob(YOUR IMAGE URL).then((response) => console.log(response) );
thank you for quick reply, i am using typescript
it look work, i am trying
with correct typings:
static async prefetchBlob(
source: string,
options?: DownloadOptions
): Promise<string | undefined> {
const path = await CacheManager.get(source, options).getPath();
if (path) {
const blob = await FileSystem.readFile(path, 'base64');
return blob;
}
return undefined;
}
If it works, please use patch-package
and patch it until we release a version that supports this.
@efstathiosntonas It work, thank you
ok great, I'll release a new version in a while including this.
@youniaogu released 2.3.0