node.js - 未处理的承诺拒绝:TypeError:网络请求失败的博览会文件上传
问题描述
我尝试将图片上传到远程服务器。我正在使用 Expo React Native。有我用来拍摄和上传图片的功能。
async function takeAndUploadPhotoAsync() {
let result = await ImagePicker.launchCameraAsync({
allowsEditing: true,
aspect: [4, 3],
});
if (result.cancelled) {
return;
}
let localUri = result.uri;
let filename = localUri.split("/").pop();
let match = /\.(\w+)$/.exec(filename);
let type = match ? `image/${match[1]}` : `image`;
let formData = new FormData();
formData.append("photo", { uri: localUri, name: filename, type });
return await fetch("https://rare-zebra-23.loca.lt/api", {
mode: "no-cors", // no-cors, *cors, same-origin
method: "POST",
body: formData,
headers: {
"content-type": "multipart/form-data",
},
});
我正在为我的服务器使用本地隧道。当我尝试获取时,我的 console.log [Unhandled promise reject: TypeError: Network request failed] 中有这个错误。GET 方法工作正常。我还使用常规的 Web 服务器检查了我的后端,它工作正常。而且世博会还有 FileSystem.uploadAsync() 方法,在我看来这也不起作用。也许有人可以解释为什么?或有一些工作示例。谢谢。
解决方案
推荐阅读
- java - 使用@Profile 决定执行测试类
- mariadb - 如何进行复制并仅修改 MariaDB 中的某些数据?
- html - 如何让 Flexbox 响应式响应?
- python - 一个更紧凑的 __repr__ 用于我的 numpy 数组?
- ios - 将肥皂体中的布尔值作为参数发送
- c# - WPF Datagridtextcolumn排序在设置sortmember路径后第一次单击时不起作用
- ios - 有没有办法通过代码动态获取应用组ID?
- mysql - 根据parrentid从同一张表中获取值
- c - 将 .wav 文件转换为单声道(删除右声道)
- javascript - javascript中类的异步函数