openimsdk / open-im-sdk-reactnative

IM ReactNative
MIT License
38 stars 54 forks source link

[BUG] Sending high-resolution images causes the app to crash #37

Closed OrrinHatch closed 6 days ago

OrrinHatch commented 1 month ago

OpenIM Server Version

3.8.0

Operating System and CPU Architecture

Linux (AMD)

Deployment Method

Docker Deployment

Bug Description and Steps to Reproduce

const selectImage = async () => {
    // 请求访问媒体库的权限
    const { granted } = await requestMediaLibraryPermissionsAsync();
    if (!granted) {
      Alert.alert('Permissions denied!');
      return;
    }
    // 打开图片库
    const resp = await launchImageLibraryAsync({
      mediaTypes: MediaTypeOptions.Images,
      allowsMultipleSelection: false,
      selectionLimit: 1,
      quality: 0.75, // 保持高质量,但后续我们会进行压缩
    });

    if (resp.canceled) {
      return;
    }
    if (resp.assets && resp.assets.length > 0) {
      let { uri } = resp.assets[0];

      if (uri) {
        if (uri.startsWith('file://')) {
          uri = uri.substring(7);
        }

        // 创建图片消息并发送
        const message = await OpenIMSDKRN.createImageMessageFromFullPath(uri, uuidv4());
        sendMessage({ message });
      }
    }
  };

Screenshots Link

No response

OrrinHatch commented 1 month ago

quality can not set 1 or 0.9

lgz5689 commented 1 month ago

If you choose a high-resolution image, what might go wrong? Can you locate the specific function?

OrrinHatch commented 1 month ago
截屏2024-09-12 18 54 23
OrrinHatch commented 1 month ago

When executing this line : const successMessage = await OpenIMSDKRN.sendMessage(options, uuidv4());

daxingyun commented 1 month ago

这个问题解决了吗?

daxingyun commented 1 month ago

我有个一样的问题,发送图片消息必然崩溃,反复测试过:与压缩,和图片大小应该是没有关系的。比如发送1M 以及压缩至100KB ,发送都会崩溃。 目前我的解决方案是通过OpenIMSDKRN.uploadFile先上传,再通过OpenIMSDKRN.sendMessage发送图片消息。但这个方案无法读取进度条。期待尽快解决!

daxingyun commented 1 month ago

@OrrinHatch 谢谢。。

OrrinHatch commented 1 month ago

@daxingyun 或者 在这个文件 https://github.com/openimsdk/open-im-sdk-reactnative/blob/main/android/src/main/java/com/openimsdkrn/SendMsgCallBack.java

OrrinHatch commented 1 month ago
截屏2024-09-23 15 53 10
daxingyun commented 1 month ago

@OrrinHatch 我的问题似乎已经解决了,我修改的代码:params.putMap("message", Arguments.makeNativeMap(message.toHashMap())); ,copy()是不存在的函数。谢谢。。。