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 <pfrazee@gmail.com>
This commit is contained in:
Ansh 2023-07-03 11:17:12 -07:00 committed by GitHub
parent 7cf0db7d14
commit edff1992b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 26 deletions

View file

@ -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<Dimensions> {