解决相册/拍照文件上传问题

相册获取文件格式: /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

 

拍照上传的时候携带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);
    });
}

 

解决相册/拍照文件上传问题

上一篇:Apache atlas liunx环境安装部署手册


下一篇:C语言练习stack