【问题标题】:React Native Weird android behaviour displaying uploaded images显示上传图像的 React Native 奇怪的 android 行为
【发布时间】:2017-11-02 16:50:46
【问题描述】:

我们正在使用 React Native 和 react-native-image-picker 库构建一个应用程序。

我将从我们现在的行为开始: (在 Android 设备上)上传图像选择器库选择的图像(个人资料图像)时,一切顺利。 在返回个人资料页面的请求之后,我们刚刚上传的图像没有被加载。重新启动/构建/清除缓存无法解决问题。

在同一帐户上查看我的 iOS 模拟器/Android 模拟器时,我确实看到了从设备上传的图像。

tl:dr 我从安卓设备上传了一张图片,(上传正确,可以在浏览器中看到)在同一台设备上看不到,但我可以在其他设备/模拟器上看到。

我不知道发生了什么,希望得到一个快速的答案,因为问题是延迟发布。

这是我从图像选择器中获取图像的地方。

ImagePicker.showImagePicker(options, (response) => {
  if (response.error) {
    this.props.setError(I18n.t('editProfile.fields.profileImage.error'));
  } else if (!response.didCancel) {
    if (Platform.OS === 'ios') {
      const image = {
        uri: response.uri.replace('file://', ''),
        filename: 'ProfileImage',
        height: response.height,
        isStored: false,
        width: response.width,
      };

      this.props.onSubmit(image);
    } else {
      const image = {
        uri: response.path,
        filename: 'ProfileImage',
        height: response.height,
        isStored: true,
        width: response.width,
      };

      this.props.onSubmit(image);
    }
  }
});

注意:此功能在 iOS 上完美运行。

【问题讨论】:

  • 你用什么uri来显示提交的图片?
  • 我正在使用亚马逊 s3 网址。
  • 提交按钮是上传功能

标签: android image react-native react-native-android


【解决方案1】:

我在使用 AWS S3 时遇到了类似的问题,但在我的情况下,问题是没有设置内容类型/mime 类型。我不得不手动设置它。

这是我的代码的一部分:

s3 = new AWS.S3();

      var extension = ".jpg";
      if (img.mime.indexOf(".png") > -1)
        extension = ".png";

      var key = "Reports/" + req.body.id + "/" + date.getTime() + "/Image" + extension;

      var buf = new Buffer(img.data,'base64');

      var params = {
        Bucket: 'XXXXXXXXXXXXX',
        Key: key,
        Body: buf,
        ContentEncoding: 'base64',
        ContentType: img.mime,
        ACL: 'public-read'
      };

      console.log("S3 Start");
      var upload = s3.upload(params, function(err,data) {
        if (err) {
          console.log(err, err.stack);
        } else {
          console.log(data);
          s3Url = data.Location;
        }

【讨论】:

  • 这不会导致它不显示在其他设备上吗?
  • 我记得发生在我身上的是图像被下载而不是显示,因为它被检测为八位二进制文​​件。但有些浏览器实际上显示了图像。我只提到这一点是因为您说您使用的是 S3。图片实际上是否正确上传?
  • 是的,图片上传正确,它显示在其他设备和模拟器上。
【解决方案2】:

问题是根据上传的图片引起的。 旧的安卓设备似乎有问题。

【讨论】:

  • 我有同样的问题,无法在Andorid中显示捕获的图像,它在iOS中完美运行,您能分享一下您是如何解决的吗?
猜你喜欢
  • 1970-01-01
  • 2019-01-30
  • 1970-01-01
  • 2019-03-22
  • 2021-07-13
  • 1970-01-01
  • 2015-05-21
  • 2021-06-01
  • 2012-12-24
相关资源
最近更新 更多