fix: use 'file' field name with proper MIME type for attach endpoint
This commit is contained in:
@@ -109,11 +109,11 @@ function ivantiFormPost(urlPath, fields, files, apiKey, skipTls) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// File fields
|
// File fields
|
||||||
for (const { name, buffer, filename } of files) {
|
for (const { name, buffer, filename, contentType } of files) {
|
||||||
parts.push(Buffer.from(
|
parts.push(Buffer.from(
|
||||||
`--${boundary}\r\n` +
|
`--${boundary}\r\n` +
|
||||||
`Content-Disposition: form-data; name="${name}"; filename="${filename}"\r\n` +
|
`Content-Disposition: form-data; name="${name}"; filename="${filename}"\r\n` +
|
||||||
`Content-Type: application/octet-stream\r\n\r\n`
|
`Content-Type: ${contentType || 'application/octet-stream'}\r\n\r\n`
|
||||||
));
|
));
|
||||||
parts.push(buffer);
|
parts.push(buffer);
|
||||||
parts.push(Buffer.from('\r\n'));
|
parts.push(Buffer.from('\r\n'));
|
||||||
|
|||||||
@@ -1048,10 +1048,10 @@ function createIvantiFpWorkflowRouter(db, requireAuth) {
|
|||||||
console.log('[attachFiles] Uploading', files.length, 'files to', attachUrl);
|
console.log('[attachFiles] Uploading', files.length, 'files to', attachUrl);
|
||||||
|
|
||||||
for (const f of files) {
|
for (const f of files) {
|
||||||
console.log('[attachFiles] Uploading:', f.originalname, 'size:', f.size);
|
console.log('[attachFiles] Uploading:', f.originalname, 'size:', f.size, 'mimetype:', f.mimetype);
|
||||||
try {
|
try {
|
||||||
// Use ivantiFormPost with field name 'files' (same as create endpoint)
|
// Use ivantiFormPost with field name 'file' and proper MIME type
|
||||||
const formFiles = [{ name: 'files', buffer: f.buffer, filename: f.originalname }];
|
const formFiles = [{ name: 'file', buffer: f.buffer, filename: f.originalname, contentType: f.mimetype || 'application/octet-stream' }];
|
||||||
const result = await ivantiFormPost(attachUrl, [], formFiles, apiKey, skipTls);
|
const result = await ivantiFormPost(attachUrl, [], formFiles, apiKey, skipTls);
|
||||||
console.log('[attachFiles] Result for', f.originalname, '— status:', result.status, 'body:', (result.body || '').substring(0, 200));
|
console.log('[attachFiles] Result for', f.originalname, '— status:', result.status, 'body:', (result.body || '').substring(0, 200));
|
||||||
const success = result.status === 200 || result.status === 201 || result.status === 202;
|
const success = result.status === 200 || result.status === 201 || result.status === 202;
|
||||||
|
|||||||
Reference in New Issue
Block a user