gpt4 book ai didi

reactjs - rn-fetch-blob 错误 : RNFetchBlob. fetchBlobForm 未能创建请求正文

转载 作者:行者123 更新时间:2023-12-03 23:27:42 28 4
gpt4 key购买 nike

async postFileUpload(payload) {
const rnfetchfile = RNFetchBlob.wrap(payload.uri);
try {
console.log(
'POST',
'https://******.***.**/******/***/upload_*******_file',
{
...this.config,
'Content-Type': 'multipart/form-data',
},
[
// element with property `filename` will be transformed into `file` in form data
{
name: 'files',
filename: payload.name,
data: rnfetchfile.replace('file://file:///', 'file://'),
},
],
);
const res = await RNFetchBlob.fetch(
'POST',
'https://******.***.**/******/***/upload_*******_file',
{
...this.config,
'Content-Type': 'multipart/form-data',
},
[
// element with property `filename` will be transformed into `file` in form data
{
name: 'files',
filename: payload.name,
data: rnfetchfile.replace('file://file:///', 'file://'),
},
],
);
const response = JSON.parse(res.data);
console.log('api upload adpostimage', response);
return response;
} catch (err) {
console.log('postFileUpload', err.response, err);
Toast.show(err.response.data.message, Toast.SHORT);
throw err.response.data;
}

res 抛出错误
在控制台消息是
POST https://******.***.**/******/***/upload_*******_file {Content-Type: "multipart/form-data", Authorization: "Bearer ******.***.*****"} 
[{…}]
0:
name: "files"
filename: "*****.pdf"
data: "RNFetchBlob-file://Users/********/tmp/*****/B****.pdf"}
postFileUpload undefined Error: RNFetchBlob.fetchBlobForm failed to create request body
at index.js:313
at MessageQueue.__invokeCallback (MessageQueue.js:483)
at MessageQueue.js:135
at MessageQueue.__guard (MessageQueue.js:384)
at MessageQueue.invokeCallbackAndReturnFlushedQueue (MessageQueue.js:134)
at debuggerWorker.js:69

我正在尝试使用 rn-fetch-blob 上传文件,但发生了一些疯狂的事情
rnfetchfile.replace('file://file:///', 'file://'), 因为 file://file///输出似乎不对
我认为这主要是 ios 问题,请大家帮帮我

最佳答案

here说只是用 decodeURIComponent(uri)
这是我的代码:

const realPath = Platform.OS === 'ios' ? uri.replace('file://', '') : uri;

const data = [
{
name: 'file',
filename,
type,
data: RNFetchBlob.wrap(decodeURIComponent(realPath)),
},
{name: 'bla', data: 'bla'}
]

关于reactjs - rn-fetch-blob 错误 : RNFetchBlob. fetchBlobForm 未能创建请求正文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60186820/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com