Describe the problem/error/question
I am creating a custom node where one of the operations is a file upload. I want to let the users insert a binary file just like many other nodes. One of the problem is that all those nodes are using the programmatic style.
We chose to build the node using the declarative style. Now, we can’t seem to find a way to make it work using this style. Is it even possible or do we have to swap the style to the programmatic style?
We send the file as a multipart/form-data
with the key documents
.
What is the error message (if any)?
Can’t find the way of structuring the operation without getting Invalid Syntax
.
Code:
Node Properties:
{
displayName: 'Binary Property',
name: 'binaryPropertyName',
type: 'string',
displayOptions: {
show: {
operation: ['uploadDocument'],
},
},
default: 'data',
required: true,
description:
'Name of the binary property containing the file to upload. Usually `data` when coming from another node (e.g., HTTP Request).',
placeholder: 'data',
},
Try number 1:
export const uploadDocument: INodePropertyOptions = {
name: 'Upload a Document',
value: 'uploadDocument',
description: 'Upload a document to associate with an entity',
action: 'Upload a Document',
routing: {
request: {
method: 'POST',
url: '=/documents/upload?{{ $parameter.idType }}={{ $parameter.id }}',
headers: {
'Content-Type': 'multipart/form-data',
},
body: {
mode: 'formData',
formData: [
{
documents: {
uri: '={{ $parameter.binaryPropertyName.binary.data}}',
name: '={{ $parameter.binaryPropertyName.binary.fileName }}',
type: '={{ $parameter.binaryPropertyName.binary.mimeType }}',
},
},
],
},
},
output: {
postReceive: [
{
type: 'set',
properties: {
value: '={{ $response.body }}',
},
},
],
},
},
};
Try number 2:
export const uploadDocument: INodePropertyOptions = {
name: 'Upload a Document',
value: 'uploadDocument',
description: 'Upload a document to associate with an entity',
action: 'Upload a Document',
routing: {
request: {
method: 'POST',
url: '=/documents/upload?{{ $parameter.idType }}={{ $parameter.id }}',
headers: {
'Content-Type': 'multipart/form-data',
},
body: {
mode: 'formData',
formData: [
{
parameterType: 'formBinaryData',
name: 'documents',
inputDataFieldName: '={{ $parameter.binaryPropertyName }}',
},
],
},
},
output: {
postReceive: [
{
type: 'set',
properties: {
value: '={{ $response.body }}',
},
},
],
},
},
};
Thank you!