蒸发.js 没有从移动设备发送 to_sign
Posted
技术标签:
【中文标题】蒸发.js 没有从移动设备发送 to_sign【英文标题】:evaporate.js not sending to_sign from mobile device 【发布时间】:2021-09-02 19:42:57 【问题描述】:我正在开发一个具有 Web 和移动 UI 组件的应用程序。我们正在使用evaporate.js 调用一个端点,该端点将返回一个预签名的url,用于将块上传到aws 存储桶。这个概念在 react 中使用时有效,它发送 to_sign
查询字符串参数来创建 pre-signed
url。出于某种原因,当从 react native 运行此代码时,to_sign
查询字符串值不会传递到端点。什么可能阻止 to_sign
参数从蒸发传递,同样的代码适用于反应应用程序?这是我们从 react native 调用的代码:
const uploader = Evaporate.create(
signerUrl: config.SIGNER_URL,
aws_key: config.AWS_KEY,
bucket: config.BUCKET,
awsRegion: config.AWS_REGION,
cloudfront: true,
xhrWithCredentials: true,
computeContentMd5: true,
cryptoMd5Method: (d) => btoa(sparkMD5.ArrayBuffer.hash(d, true)),
cryptoHexEncodedHash256: sha256,
);
const uploadFile = (file, cb) =>
setLoading(true);
setUploadingError("");
let newName = uuidv4();
let extension = file.name.split(".");
uploader
.then((evaporate) =>
evaporate
.add(
file,
name: newName + "." + extension[2],
)
.then((res, err) =>
if (res)
cb(res);
setLoading(false);
else if (err)
setUploadingError("Something went wrong");
setLoading(false);
);
)
.catch((err) =>
setUploadingError("Something went wrong");
setLoading(false);
);
;
不确定这是否是一个范围,但移动版本没有提供 CORS 的 url,而不是 CORS s3 管理屏幕上设置的 url,所以这可能是 CORS 问题吗?
【问题讨论】:
to_sign
查询参数应该从哪里来?它未在文档中列出:github.com/TTLabs/EvaporateJS/wiki/Evaporate.create()
从我在调用 Evaporate.create 承诺时所看到的情况来看,对于我的网络版本,在内部,它在调用 signerUrl 以获取预签名的 url 时发送它。我可以看到它被传递到生成预签名 url 的端点。
您使用的是哪个版本的Evaporate
?您可以在package.json
或package-lock.json
中获得确切的版本
“蒸发”:“^2.1.4”
网页版和手机版使用的是同一个版本。
【参考方案1】:
我怀疑这是因为 btoa 在 react-native 中不起作用。因为反应原生 在浏览器中使用不同的 js 引擎。一些 js 代码在浏览器中是可执行的,但在 rn 中是不能执行的。尝试自己实现btoa。
有一个类似的问题React Native atob() / btoa() not working without remote JS debugging
【讨论】:
以上是关于蒸发.js 没有从移动设备发送 to_sign的主要内容,如果未能解决你的问题,请参考以下文章
如何从移动设备上的移动设备获取 console.log 输出?
如何将数据从 Android 移动设备发送到 Google App Engine 数据存储区?