mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
feat(Matrix Node): Allow setting filename if the binary data has none (#6536)
This commit is contained in:
parent
b66d151066
commit
8b76e98085
|
@ -189,6 +189,7 @@ export async function handleMatrixCall(
|
||||||
const roomId = this.getNodeParameter('roomId', index) as string;
|
const roomId = this.getNodeParameter('roomId', index) as string;
|
||||||
const mediaType = this.getNodeParameter('mediaType', index) as string;
|
const mediaType = this.getNodeParameter('mediaType', index) as string;
|
||||||
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', index);
|
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', index);
|
||||||
|
const additionalFields = this.getNodeParameter('additionalFields', index);
|
||||||
|
|
||||||
let body;
|
let body;
|
||||||
const qs: IDataObject = {};
|
const qs: IDataObject = {};
|
||||||
|
@ -197,7 +198,12 @@ export async function handleMatrixCall(
|
||||||
const { fileName, mimeType } = this.helpers.assertBinaryData(index, binaryPropertyName);
|
const { fileName, mimeType } = this.helpers.assertBinaryData(index, binaryPropertyName);
|
||||||
body = await this.helpers.getBinaryDataBuffer(index, binaryPropertyName);
|
body = await this.helpers.getBinaryDataBuffer(index, binaryPropertyName);
|
||||||
|
|
||||||
qs.filename = fileName;
|
if (additionalFields.fileName) {
|
||||||
|
qs.filename = additionalFields.fileName as string;
|
||||||
|
} else {
|
||||||
|
qs.filename = fileName;
|
||||||
|
}
|
||||||
|
|
||||||
headers['Content-Type'] = mimeType;
|
headers['Content-Type'] = mimeType;
|
||||||
headers.accept = 'application/json,text/*;q=0.99';
|
headers.accept = 'application/json,text/*;q=0.99';
|
||||||
|
|
||||||
|
@ -216,7 +222,7 @@ export async function handleMatrixCall(
|
||||||
|
|
||||||
body = {
|
body = {
|
||||||
msgtype: `m.${mediaType}`,
|
msgtype: `m.${mediaType}`,
|
||||||
body: fileName,
|
body: qs.filename,
|
||||||
url: uploadRequestResult.content_uri,
|
url: uploadRequestResult.content_uri,
|
||||||
};
|
};
|
||||||
const messageId = uuid();
|
const messageId = uuid();
|
||||||
|
|
|
@ -81,8 +81,30 @@ export const mediaFields: INodeProperties[] = [
|
||||||
description: 'Image media type',
|
description: 'Image media type',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
description: 'Name of the uploaded file',
|
description: 'Type of file being uploaded',
|
||||||
placeholder: 'mxc://matrix.org/uploaded-media-uri',
|
placeholder: 'mxc://matrix.org/uploaded-media-uri',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Additional Fields',
|
||||||
|
name: 'additionalFields',
|
||||||
|
type: 'collection',
|
||||||
|
placeholder: 'Add Field',
|
||||||
|
default: {},
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: ['media'],
|
||||||
|
operation: ['upload'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'File Name',
|
||||||
|
name: 'fileName',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: 'Name of the file being uploaded',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in a new issue