我正在尝试发出对ShortPixel的请求,以防它是一个包含多部分/表单数据的请求,并收到返回
{ Status: { Code: -115, Message: 'Uploaded files are missing.' } } }接口链接https://shortpixel.com/api-docs#reducer-api-params
const FormData = require("form-data")
const axios = require('axios')
const data = new FormData();
const url = 'https://api.shortpixel.com/v2/post-reducer.php'
const config = { headers: {
'accept': 'application/json',
'Accept-Language': 'en-US,en;q=0.8',
'Content-Type': `multipart/form-data; boundary=${data._boundary}`,
}}
data.append('hiroshi.png', fs.createReadStream("/home/hiroshi/Documents/projetos/compress/imagens/original/hiroshi.png"), 'hiroshi.png');
axios.post(url,options,{formData:data}, config)
.then((response) => {
console.log(response)
}).catch((error) => {
console.log(error)
});发布于 2019-01-16 19:08:04
我不确定用多部分表单数据请求是什么意思。我只是将表单数据收集到服务器端的一个对象中,并像这样发送它:
let postData = {
"key": "api_key_here",
"plugin_version": "JS123",
"lossy": 1,
"cmyk2rgb": 1,
"refresh": 1,
"resize": 3,
"wait":30,
"resize_width":100,
"resize_height":100,
"urllist":["http://example.com/example.png", "http://example.com/example2.png"]
}
axios.post('https://api.shortpixel.com/v2/reducer.php',postData, {
headers: {
"Content-Type": "application/json"
}
})
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.log(error);
});您可以添加我在上面创建的postData对象的任何变量。
编辑:哦,我明白了,您使用的是post-reducer api,而上面我只使用了reducer。你解决了吗?
https://stackoverflow.com/questions/53473262
复制相似问题