【问题标题】:`allowsMultipleSelection: true` throws error in expo-image-picker (expo SDK 46)`allowsMultipleSelection: true` 在 expo-image-picker (expo SDK 46) 中抛出错误
【发布时间】:2022-12-13 19:49:18
【问题描述】:

我使用allowsMultipleSelection: false一次选择一张图片没有问题。但是对于allowsMultipleSelection: true,它会抛出一个错误。 注意:我有allowsEditing: false

发生了什么

我收到此错误:"code":"ERR_INVALID_MEDIA_TYPE","message":"Cannot handle 'public.jpeg' media type" 不确定'public.jpeg'来自哪里,因为我正在选择,从我的 iPhone 模拟器(iOS 15.5),来自不同相册的不同类型的图片,并且我选择的任何图片的错误都是相同的。 我愿意不是allowsMultipleSelection: false时出现这个错误。

语境:
反应 18
世博会 SDK 46
Expo-image-picker": "~13.3.1",
iOS 15.5 iPhone模拟器
打字稿:4.8.2

我试过的事情

  • 我运行expo doctor来检查依赖项是否有问题,但没有。
  • 尝试添加其他选项,例如base64: true、不同的质量等
  • 注意:当我打开位于expo-image-picker/plugin/tsconfig.jsonnode_modules 文件夹时,此行出现错误:"extends": "expo-module-scripts/tsconfig.base",因为找不到文件。所以我手动安装了expo-module-scripts,现在错误消失了,而是生成了行"extends": "expo-module-scripts/tsconfig.plugin"。 以上并没有改变任何东西——我在选择多张图片时遇到同样的错误(ERR_INVALID_MEDIA_TYPE)。

套餐:

最小的可重现示例

import React from 'react'
import { launchImageLibraryAsync, MediaTypeOptions } from 'expo-image-picker'
import { View, Button } from 'react-native'

export function GalleryImagesForm(props) {
  const pickImages = async () => {
    // No permissions request is necessary for launching the image library
    try {
      let result = await launchImageLibraryAsync({
        mediaTypes: MediaTypeOptions.All,
        allowsMultipleSelection: true,
      })

      console.log(result)
    } catch (error) {
      console.log(error)
    }
  }
  return (
    <View>
      <Button title="Pick an image from camera roll" onPress={pickImages} />
    </View>
  )
}

【问题讨论】:

  • 我刚刚对此进行了测试,如果您删除 mediaTypes,错误就会消失。我能想到发生这种情况的唯一原因是 jpeg 具有 .jpeg 和 .jpg 作为文件类型,也许 MediaTypeOptions.All 只涵盖其中之一?
  • 嘿,非常感谢,这很有趣 - 我删除了它但我仍然有错误,只是错误消息的扩展名发生了变化:Cannot handle 'public.jpeg' media typeCannot handle 'public.png' media type :/(不同的图片图片有该消息及其扩展名)

标签: typescript react-native image upload expo


【解决方案1】:

你有没有找到解决方案,因为我有同样的问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-04
    • 2020-03-02
    • 2022-12-10
    • 1970-01-01
    • 2022-09-25
    • 2022-11-01
    • 2018-08-08
    相关资源
    最近更新 更多