Hi @Shriket_Panchal
Thanks for responding. I understand there are 2 subsequent requests needed to upload a file to MFR, I am trying now to replicate the 1st one in n8n. Here is my code:
let bodyUploadDocument: Buffer;
let filename = 'file';
let mimeType = 'application/octet-stream';
if (this.getNodeParameter('binaryData', i)) {
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
this.helpers.assertBinaryData(i, binaryPropertyName);
const fileData = items[i].binary?.[binaryPropertyName];
bodyUploadDocument = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
if (fileData?.fileName) {
filename = fileData.fileName;
}
if (fileData?.mimeType) {
mimeType = fileData.mimeType;
}
} else {
bodyUploadDocument = Buffer.from(this.getNodeParameter('fileContent', i) as string, 'utf8');
filename = 'file.txt';
mimeType = 'text/plain';
}
const form = new FormData();
form.append('file', bodyUploadDocument, {
filename,
contentType: mimeType,
});
form.append('options', JSON.stringify({ filename }));
const endpoint = `https://portal.mobilefieldreport.com/mfr/Document/UploadAndCreate`;
const options = {
method: 'POST',
body: form,
headers: form.getHeaders(),
uri: endpoint,
json: false,
} satisfies IRequestOptions;
console.log(options)
const firstRequestResponse = await this.helpers.requestWithAuthentication.call(
this,
'mfrApi',
options,
);
console.log(firstRequestResponse)
the request’s options look like this:
{
method: 'POST',
body: FormData {
_overheadLength: 272,
_valueLength: 13288,
_valuesToMeasure: [],
writable: false,
readable: true,
dataSize: 0,
maxDataSize: 2097152,
pauseStreams: true,
_released: false,
_streams: [
'----------------------------799393174586832991107736\r\n' +
'Content-Disposition: form-data; name="file"; filename="dummy.pdf"\r\n' +
'Content-Type: application/pdf; qs=0.001\r\n' +
'\r\n',
[Buffer [Uint8Array]],
[Function: bound ],
'----------------------------799393174586832991107736\r\n' +
'Content-Disposition: form-data; name="options"\r\n' +
'\r\n',
'{"filename":"dummy.pdf"}',
[Function: bound ]
],
_currentStream: null,
_insideLoop: false,
_pendingNext: false,
_boundary: '--------------------------799393174586832991107736'
},
headers: {
'content-type': 'multipart/form-data; boundary=--------------------------799393174586832991107736'
},
uri: 'https://portal.mobilefieldreport.com/mfr/Document/UploadAndCreate',
json: false
}
However, I get this error: Cannot read properties of null (reading ‘name’).
Can you help me understand why I can’t replicate the 1st MFR request in n8n?
Thank you