尝试上传大小为(700〜)kb的图像/屏幕快照时出现错误``axios post request 413负载太大'',但是我仍然可以上传小文件。进入我的postgres数据库中的blob表。
上传功能
function readFileAsync(file) {
return new Promise((resolve, reject) => {
let reader = new FileReader();
reader.onload = () => {
var base64String = reader.result;
console.log(base64String)
console.log(base64String.substr(base64String.indexOf(',') + 1))
resolve(base64String.substr(base64String.indexOf(',') + 1));
};
reader.onerror = reject;
reader.readAsDataURL(file);
})
}
async function uploadFile(path, data) {
try {
let contentBuffer = await readFileAsync(data.chosenfile);
console.log('content buffer is'+contentBuffer)
let response = await axios({
method: 'post',
url: 'api/store/blob' + path,
headers: {'session_id': data.sessionid},
data: {"id":data.chosenfile.name, "file": contentBuffer }
});
if (response.status == 200) {
console.log(response.status);
}
return response.data;
} catch (err) {
console.error(err);
}
}
从代码中可以看到,我将文件转换为base64url,从url中,我仅发送axios有效负载中的base64字符串。请帮助?