Hello ,
I use http request node to obtain 2 jpg file , (namely (1) data and (2) data ) and merge with json key using merge node as shown below.
after which , I update the file to lark api to obtain image key as shown below with following code
const request = require('request-promise-native'); //need to reinstall n8n with variable here to use it
const x = items[0].json.key //obtain authorization key
const binaryData = items[1].binary.data; //name of file is called "data under items"
const metadata = {
name : binaryData.fileName,
}
const options = {
uri: 'https://open.larksuite.com/open-apis/image/v4/put/', //url to send http post
headers: {
'content-type': 'multipart/form-data',
'Authorization' : `Bearer ${x}`,
},
formData: {
image: {
value: Buffer.from(binaryData.data, 'base64'),
options: {
filename: binaryData.fileName,
},
},
image_type: "message" // json to appear in the body.
},
method: 'POST',
}
const response = await request(options);
return [{ json: {response} }] //display respond from http request in json.
Currently, if i want to upload 1st data file, i will use the following code
const binaryData = items[1].binary.data;
while if i want to upload 2nd data file, i will use the following code
const binaryData = items[2].binary.data;
May i know if there is anyway i could loop the file upload process so that i could return a few image key in a single execution ?
the number of file obtain from http request will depends on number of files upload by user, therefore, in certain uploads, it might be more than 2 , while in certain upload , it might be a single file.