react-native - 如何在 React-Native (Expo) 中对图像数据进行哈希处理?

标签 react-native expo

我的意图:

我希望我的应用程序将图像上传到 S3。如果图像已经存在,服务器应该记录对现有图像的引用,而不是要求上传另一个副本。

我想象这是如何工作的:

  1. 对图像数据进行哈希处理
  2. 将哈希值发送到服务器,并请求签名网址(以上传到 AWS S3)
  3. 如果哈希值与已存储的内容匹配,则引用它并告诉应用程序

初步想法:

使用imageEditor.cropImage将图像获取到ImageStore ,这会给我一个合适的 uri。然后使用 getBase64ForTag(uri, success, failure) 检索 Base64 数据以进行哈希计算。

问题:

根据这个的回答question ,这个过程一点也不高效。通常的解决方案是使用 native 方法,如对此 question 的回答中所述。 ,但是我不想为此功能弹出我的 Expo 应用程序。

我的问题:

是否有更好的方法来散列图像数据?或者更根本的是,是否有更好的方法来确保相同的图像在 S3 存储中不会重复?

最佳答案

编辑2020年10月21日:

库已自行更新,您现在应该调用:

_hashImage = async (imageUri) => {
    return await FileSystem.getInfoAsync(imageUri, { md5: true } );
}

原文:

事实证明,Expo 提供了开箱即用的功能。

Expo.FileSystem.getInfoAsync

myImageHashFunction = async (imageUri) => {
  let fsInfo = await Expo.FileSystem.getInfoAsync(imageUri, [{ md5: true }] )
  console.log(fsInfo.md5)
}

关于react-native - 如何在 React-Native (Expo) 中对图像数据进行哈希处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49725746/

相关文章:

ios - 无法在 iPad iO 上锁定屏幕方向

android - react 原生 : How to make fullscreen youtube embed video in webview with expo (without react-native link)

javascript - 使用 Map 函数编写 React 组件时,对象作为 React Child 无效

reactjs - 在 React 中动态调用方法

ios - 找不到 iPhone 6 模拟器

react-native - 导航器无法在React Native App中运行(参数0(NSNumber))

react-native - android的绝对位置

react-native - 在卡片中显示 webview( react native )

android - 在 Expo : Asyncstorage gets cleared when app refreshes 中 react 原生

android - Fresh Detached Expo + RNFirebase 未在 Android 上运行