我正在尝试将源地图上传到 Rollbar。使用curl
它可以正常工作:
curl https://api.rollbar.com/api/1/sourcemap \
-F access_token=${ACCESS_TOKEN} \
-F version=${VERSION} \
-F minified_url=${1} \
-F source_map=@${SOURCE_MAP_PATH}
但是,使用 Node 应用程序,我得到Error: Request failed with status code 413
:
const fs = require('fs');
const FormData = require('form-data');
const axios = require('axios');
const stream = fs.createReadStream('/path/to/sourcemap');
const config = {
filename: 'sourcemap',
contentType: 'application/json',
}
const formData = new FormData();
formData.append('access_token', 'the-token');
formData.append('version', '1.2.3');
formData.append('minified_url', 'https://example.com/1.2.3/minified.js');
formData.append('source_map', stream, config);
axios.post('https://api.rollbar.com/api/1/sourcemap', formData, {
headers: formData.getHeaders(),
});
这些都是完全相同的文件。不知道为什么 Node 版本不起作用。
编辑
有趣的是,如果我生成一个curl
命令,那么它就可以工作:
const execaArgs = [
'https://api.rollbar.com/api/1/sourcemap',
'-F',
'access_token=abc',
'-F',
'version=1.2.3',
'-F',
'minified_url='https://example.com/1.2.3/minified.js',
'-F',
`source_map=@${filePath}`
]
const {stdout, stderr} = await execa('curl', execaArgs);
也是如此fetch
:
fetch('https://api.rollbar.com/api/1/sourcemap', {
method: 'POST',
body: formData
})
.then(res => res.json())
.then(json => console.log(json));