react-native - iOS 上的 Rn-fetch-blob 使用 RNFetchBlob 上传图像
问题描述
我尝试使用以下代码在服务器上上传图像:
updateAvatar(token, photo) {
return postImage(
"http://lk.skilla.ru/myapi/updateAvatar",
[
{
name: "avatar",
filename: "avatar.jpg",
type: "image/jpg",
data: Platform.OS === "android" ? RNFetchBlob.wrap(photo) : photo,
},
],
token
);
},
const postImage = (url, params, token) => {
return RNFetchBlob.config({ fileCache: true, appendExt: "jpg" })
.fetch(
"POST",
url,
{ Authorization: token, "Content-Type": "multipart/form-data" },
params
)
.then((res) => {
console.log("response");
console.log(res.text());
return Platform.OS === 'android' ? 'file://' + res.path() : '' + res.path()
})
.catch((error) => console.log(error));
};
在 android 上一切正常,但在 RN-Fetch-Blob 返回的 iOS 文件上不存在。如何在iOS上包装网址?RNFetchBlob.wrap 不起作用
解决方案
这就是我让它为我工作的方式。
const filePath = Platform.OS === 'ios'
? res.path().replace('file:///', '').replace('file://', '')
: res.path().replace('file://', '').replace('file:/', '');
推荐阅读
- linux - Is there a way that a multi-threaded process can continue to run after being core dumped (SIGABRT)?
- listview - 在 App 中显示 ListView 时出现 Flutter 错误
- python - 将数据框复制到现有的 excel 文件(熊猫)
- javascript - 关闭 Internet Explorer 后 Cookie 清空
- actionscript-3 - Stacking multiple bitmaps set transparency to black
- ios - Custom TabelViewCell disappears after UITextField in cell becomes first responder
- c++ - Translate return codes SQLITE_OK, ..., SQLITE_DONE to an enum class in C++ (without ask clients to include the C header)
- google-chrome-extension - Detect tab restore event
- python - My Spyder console cannot recognize pygal once I import it
- python - 熊猫数据框中的Covent json