相冊獲取文件格式: /storage/emulated/0/Huawei/MagazineUnlock/magazine-unlock-06-2.3.8702-6017C013F9C1232C2D596A27F0F9E3B4.(jpg/png/mp4...)
拍照/錄像獲取文件格式: file:///data/user/0/com.chinacreator.hnajyjzh.app/cache/1626974674663.(jpg/png/mp4...)
拍照上傳的時候攜帶token, 改name為后端定的字段file或者別的 就成功上傳
而上傳相冊中的文件卻提示:
the request was rejected because no multipart boundary was found
解決方法:
Content-Type字段改為
multipart/form-data; boundary=8ffV5qFM0HiG0qA3JCQeeWBTSwAEsxPD
boundary只是一個邊界,里面的值無所謂
function handleUpload(params) { console.log('paramsparamsparamsparamsparams', JSON.stringify(params)); let filePath = params.file.includes('file://') ? params.file : 'file://' + params.file; cordova.plugin.http.uploadFile(`${API_BASE_URL}/fileserv/upload`, { }, { Authorization: 'OAuth2: token', 'Content-Type': 'multipart/form-data; boundary=8ffV5qFM0HiG0qA3JCQeeWBTSwAEsxPD', }, filePath, 'file', function(response) { console.log('上傳成功', JSON.stringify(response)); if(response.status === 200) { if(response.data.includes('登錄已超時')) { params.success('login timeout'); } else { params.success(JSON.parse(response.data)); } } }, function(response) { console.error('上傳失敗', response.error); }); }