fix: properly detect the mime type being passed

This commit is contained in:
Mary
2024-05-07 22:41:11 +07:00
parent a0da3a2a45
commit d2f7578769
2 changed files with 5 additions and 3 deletions
+3 -2
View File
@@ -3,8 +3,9 @@ import {
launchImageLibraryAsync, launchImageLibraryAsync,
MediaTypeOptions, MediaTypeOptions,
} from 'expo-image-picker' } from 'expo-image-picker'
import {getDataUriSize} from './util'
import * as Toast from 'view/com/util/Toast' import * as Toast from 'view/com/util/Toast'
import {getDataUriSize} from './util'
export async function openPicker(opts?: ImagePickerOptions) { export async function openPicker(opts?: ImagePickerOptions) {
const response = await launchImageLibraryAsync({ const response = await launchImageLibraryAsync({
@@ -26,7 +27,7 @@ export async function openPicker(opts?: ImagePickerOptions) {
return false return false
}) })
.map(image => ({ .map(image => ({
mime: 'image/jpeg', mime: image.mimeType || 'image/jpeg',
height: image.height, height: image.height,
width: image.width, width: image.width,
path: image.uri, path: image.uri,
+2 -1
View File
@@ -91,6 +91,7 @@ export async function pasteImage(
uri: string, uri: string,
): Promise<ComposerImageWithoutTransformation> { ): Promise<ComposerImageWithoutTransformation> {
const {width, height} = await getImageDim(uri) const {width, height} = await getImageDim(uri)
const match = /^data:(.+?);/.exec(uri)
return { return {
alt: '', alt: '',
@@ -98,7 +99,7 @@ export async function pasteImage(
path: uri, path: uri,
width: width, width: width,
height: height, height: height,
mime: 'image/jpeg', mime: match ? match[1] : 'image/jpeg',
}, },
} }
} }