How to copy attachment field to new record ?

I get fileKey and create new record

var fileKey = kintone.app.record.get().record.file.value[0].fileKey;

example

var body = {
“app”: 988,
“id”: 31,
“record”: {
“Attachment”: {
“value”:

| [ |
|   | { |
|   | “fileKey”: fileKey |
|   | } |
|   | ] |

}
}
}

kintone.api(kintone.api.url(’/k/v1/record’, true), ‘PUT’, body, function(resp) {
// success
console.log(‘Success’);
}, function( error ) {
// error
console.log(JSON.stringify(error));
} );

Cannot be create

520 “message”:“Invalid fileKey parameter: 202101210454194B9C92C85793465781D02DEF8D540481020”

 

Hi NewTum,

If you want to reuse a file, you need to download the file with the API,
Then, upload the file with the API, and then use the file key to link it to other records.

 

You can download the file using the file key obtained by the kintone.app.record.get function.
The file key included in the response at the time of acquisition can only be used to download files.

 

1)Get a file key with kintone.app.record.get function method for attached files

2)Download the file with the file key at 1)

3)Get a new file key for the downloaded file

4)Upload to another record with the file key obtained at 3).

 

Download File:
https://developer.kintone.io/hc/en-us/articles/212494468-Download-File

 

Upload File:
https://developer.kintone.io/hc/en-us/articles/212494448-Upload-File
(Note that the file key obtained with the Get Record API cannot be used for file uploads.)

 

I could not find an English article about adding a new attachment file while leaving an existing one.
The following is the instruction on adding a new file to a record using JavaScript while leaving the file already registered in the record.

 

In kintone, when you make changes to a record that has already been registered, you need to reconfigure all of the field information to be changed.

 

Steps:

Suppose that a file has already been registered in the record in the following form.

Original information of the record

{
"record": {
"attached file": {
"type": "FILE",
"value": [
{
"contentType": "text/plain",
"fileKey": "201202061155587E339F9067544F1A92C743460E3D12B3297",
"name": "Existing files.txt",
"size": "23175"
}
]
}
}
}

If you want to keep the existing file and add a new one, specify as follows.

RequestData when adding a file

{
"app": 5,
"record": {
"attached file": {
"value": [
{
"fileKey": "201202061155587E339F9067544F1A92C743460E3D12B3297"
},
{
"fileKey": "78a586f2-e73e-4a70-bec2-43976a60746e"
}
]
}
}
}

Additional files can be uploaded by ‘PUT’ the above Request.

Hopefully, this helps.