From edff1992b18a62f4ada09ba4f20cd2c29cd4e634 Mon Sep 17 00:00:00 2001 From: Ansh Date: Mon, 3 Jul 2023 11:17:12 -0700 Subject: Add permission checks before saving image (#945) * catch permission errors when saving image to album * Save photos to media library alone (not an album) --------- Co-authored-by: Paul Frazee --- src/lib/media/manip.ts | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'src/lib/media/manip.ts') diff --git a/src/lib/media/manip.ts b/src/lib/media/manip.ts index 2f6c25e83..a681627e6 100644 --- a/src/lib/media/manip.ts +++ b/src/lib/media/manip.ts @@ -108,13 +108,7 @@ export async function shareImageModal({uri}: {uri: string}) { RNFS.unlink(imagePath) } -export async function saveImageToAlbum({ - uri, - album, -}: { - uri: string - album: string -}) { +export async function saveImageToMediaLibrary({uri}: {uri: string}) { // download the file to cache // NOTE // assuming PNG @@ -126,14 +120,8 @@ export async function saveImageToAlbum({ let imagePath = downloadResponse.path() imagePath = normalizePath(await moveToPermanentPath(imagePath, '.png'), true) - // save to the album (creating as needed) - const assetRef = await MediaLibrary.createAssetAsync(imagePath) - const albumRef = await MediaLibrary.getAlbumAsync(album) - if (albumRef) { - await MediaLibrary.addAssetsToAlbumAsync(assetRef, albumRef) - } else { - await MediaLibrary.createAlbumAsync(album, assetRef) - } + // save + await MediaLibrary.createAssetAsync(imagePath) } export function getImageDim(path: string): Promise { -- cgit 1.4.1