I am trying to POST to this endpoint using nodeJS's https.request() function but I'm getting a "missing file" response, however, it is able to read when I POST the clientId, so I'm thinking that "file" type inputs in multipart forms are possibly handled differently?
(我正在尝试使用nodeJS的https.request()函数发布到此端点,但是我收到“文件丢失”响应,但是,当我发布clientId时它能够读取,因此我认为该“文件”多部分形式的类型输入可能会以不同的方式处理?)
Am I not POSTing in the correct manner?(我的发布方式是否正确?)
This is the HTML form representation on the client's end that I'm POSTing too:
(这也是我也在发布的客户端端的HTML表单表示形式:)
<html><body><form action='https://example.com/foo/bar/test' method='POST' enctype='multipart/form-data'>
<input type="file" name="file">
<input type="hidden" name="clientId" value="12345">
<input type="submit" name="submit">
</form></body></html>
And this is my backend code for POSTing to it:
(这是我发布的后端代码:)
const data = JSON.stringify({
file: pathToPdf,
clientId: 6789
})
const options = {
hostname: 'example.com',
path: '/foo/bar/test',
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
auth: 'user:pass'
};
`const req = https.request(options, (res) => {
console.log('STATUS: ${res.statusCode}');
console.log('HEADERS: ${JSON.stringify(res.headers)}');
res.setEncoding('utf8');
res.on('data', (chunk) => {
console.log('BODY: ${chunk}');
});
res.on('end', () => {
console.log('No more data in response.');
});
})
req.on('error', (e) => {
console.error('problem with request: ${e.message}');
});
req.write(data);
req.end();
Is there a reason why "clientId" would work but not "file"?
(有什么理由可以使“ clientId”起作用但不能使“ file”起作用?)
ask by Jakkie Chan translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…