You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

react-native-image-picker返回的response.filesize单位是字节还是比特?

react-native-image-picker中fileSize字段的单位说明

response.assets[0].fileSize的单位是字节(Bytes),并非比特(Bits)。

你获取到的数值484908,对应的就是484908字节,换算后约为473KB(484908 ÷ 1024 ≈ 473),这和你代码中设置quality: .5的图片压缩预期结果匹配。

你也可以通过base64长度反推验证:base64编码后的数据长度约为原始字节数的4/3倍。如果fileSize是484908字节,对应的base64长度大概是484908 × 4 ÷ 3 ≈ 646544,这和你代码中打印的response.assets[0].base64.length数值应该能对应上,进一步佐证fileSize的单位是字节。

代码示例

try{  
  let options = {
    mediaType: 'photo',
    maxWidth: 1280,
    maxHeight: 720,
    quality: .5,
    includeBase64:true
  };

   const reso = launchImageLibrary(options, (response) => {
    console.log('Response = ', response);

    if (response.didCancel) {
      alert('User cancelled camera picker');
      return;
    } else if (response.errorCode == 'camera_unavailable') {
      alert('Camera not available on device');
      return;
    } else if (response.errorCode == 'permission') {
      alert('Permission not satisfied');
      return;
    } else if (response.errorCode == 'others') {
      alert(response.errorMessage);
      return;
    }
    // console.log('base64 -> ', response.assets[0].base64);
    console.log('uri -> ', response.assets[0].uri);
    console.log('width -> ', response.assets[0].width);
    console.log('height -> ', response.assets[0].height);
    console.log('fileSize -> ', response.assets[0].fileSize);
    console.log('type -> ', response.type);
    console.log('fileName -> ', response.fileName);
    console.log("base 64 length ",response.assets[0].base64.length)
    setCompressedImage(response.assets[0].uri)
   
  });

内容的提问来源于stack exchange,提问作者Muhammad Ibrahim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 12:05:42