Skip to content

Commit

Permalink
Merge pull request #3201 from bluesky-social/samuel/handle-invalid-files
Browse files Browse the repository at this point in the history
Filter out non-image files from image picker
  • Loading branch information
mozzius authored Mar 13, 2024
2 parents f1d55f4 + 8c7f813 commit 44b3a37
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/lib/media/picker.shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ export async function openPicker(opts?: ImagePickerOptions) {
Toast.show('You may only select up to 4 images')
}

return (response.assets ?? []).slice(0, 4).map(image => ({
mime: 'image/jpeg',
height: image.height,
width: image.width,
path: image.uri,
size: getDataUriSize(image.uri),
}))
return (response.assets ?? [])
.slice(0, 4)
.filter(asset => {
if (asset.mimeType?.startsWith('image/')) return true
Toast.show('Only image files are supported')
return false
})
.map(image => ({
mime: 'image/jpeg',
height: image.height,
width: image.width,
path: image.uri,
size: getDataUriSize(image.uri),
}))
}

0 comments on commit 44b3a37

Please sign in to comment.