This commit is contained in:
Eric Bailey
2025-08-15 16:44:21 -05:00
parent 28e5ff0e7a
commit 0280871b2a
+10 -13
View File
@@ -207,12 +207,10 @@ function classifyImagePickerAsset(asset: ImagePickerAsset):
function dataURItoBlob(uri: string, mimeType: string) { function dataURItoBlob(uri: string, mimeType: string) {
const [, data] = uri.split(',') const [, data] = uri.split(',')
const binary = atob(data) const binary = atob(data)
// Convert to array of bytes
const array = new Uint8Array(binary.length) const array = new Uint8Array(binary.length)
for (let i = 0; i < binary.length; i++) { for (let i = 0; i < binary.length; i++) {
array[i] = binary.charCodeAt(i) array[i] = binary.charCodeAt(i)
} }
// Create and return the Blob
return new Blob([array], {type: mimeType}) return new Blob([array], {type: mimeType})
} }
@@ -237,15 +235,6 @@ async function getMetadata(
} }
> { > {
const mime = mimeType || extractDataUriMime(uri) const mime = mimeType || extractDataUriMime(uri)
const blob = dataURItoBlob(uri, mime)
if (blob.size > VIDEO_MAX_SIZE) {
return {
error: GetMetadataError.FileTooLarge,
asset: undefined,
}
}
const ext = mimeToExt(mime) const ext = mimeToExt(mime)
if (!ext) { if (!ext) {
@@ -255,15 +244,23 @@ async function getMetadata(
} }
} }
const blob = dataURItoBlob(uri, mime)
if (blob.size > VIDEO_MAX_SIZE) {
return {
error: GetMetadataError.FileTooLarge,
asset: undefined,
}
}
const file = new File([blob], `tmp.${ext}`, { const file = new File([blob], `tmp.${ext}`, {
type: mime, type: mime,
}) })
if (!file) {
if (!file)
return { return {
error: GetMetadataError.FileCreationFailure, error: GetMetadataError.FileCreationFailure,
asset: undefined, asset: undefined,
} }
}
try { try {
const asset = await getVideoMetadata(file) const asset = await getVideoMetadata(file)