javascript - HostFunction 中的异常:使用 fetch 在 React Native 上上传图像时来自 JS 的错误调用
问题描述
我正在尝试使用 fetch 将图像上传到服务器,它在 Android 上运行良好,但在 iOS 上出现错误,上传确实有效,但始终显示此错误。
export const uploadImage = async (image: Response, organisation: string, tokenData: any) => {
if (image.data) {
const JWT = pathOr('', ['getFileAccessToken', 'AccessToken'], tokenData);
// image.filename doesn't exist on android
const filename = Platform.OS === 'ios' ? image.filename : image.path.split('/').pop();
const buffer = Buffer.from(image.data, 'base64');
const response = await fetch(`${config.API_ENDPOINT}/files/${filename}`, {
method: 'POST',
headers: {
Authorization: `Bearer ${JWT}`,
'Content-Type': image.mime,
'CP-Org-Name': organisation,
},
body: buffer,
});
return response.json();
}
};
解决方案
推荐阅读
- javascript - 如何在 ReactJS 中的组件之间共享数组的动态对象?
- javascript - 如何停止keydown事件被卡住?
- c# - 如何将 XML 加载到 C# WPF 树视图中
- twilio - 为什么 Twilio 呼叫转移与运营商呼叫转移的操作方式不同?
- linux - 无法将用户添加到 docker 组
- db2 - SQL 为日期传递表日期
- python - 我可以在测试用例中模拟我的函数的输入吗?
- python - 从 tf.TFRecordReader() 转移到 tf.data.TFRecordDataset 时出错
- excel - 查找某个文本,将文本下方的所有内容复制到另一个工作簿中的相同文本下
- python-3.x - 如何根据ggplot中的数据集按小时绘制活动?