Can I update image and file fields with the bulk_upsert API for content?
It is possible to update image and file fields with the bulk_upsert API for content.
You can only update the following items. Updating GCS, S3, and Vimeo items is not supported.
- Images (uploaded to KurocoFiles)
- Files (uploaded to KurocoFiles)
Preparing the zip file
To update file fields with the bulk_upsert API, you need to prepare a zip file.
Create a folder with any name and place the files you want to update directly under it. You can set any alphanumeric characters as the file names.
.
`- assets
|- File1.png
|- PdfFile.pdf
`- Image.png
Compress the created folder in zip format.
.
|- assets # Created folder
`- assets.zip # Zip file compressed from the assets folder
Uploading files using Files::upload
Use the Files::upload
API to upload the ZIP file created earlier. For detailed instructions, please refer to Uploading Files Using an API.
// Response from Files::upload
{
"file_id": "files/temp/*.zip",
"errors": []
}
Once completed, POST the following request body to Topics::bulk_upsert
.
Specify the file_id
included in the response from Files::upload
in assets_file
, and specify the names of the files you want to set in each item (file or image item) of the list
.
{
"assets_file": {
"file_id": "files/temp/*.zip" // file_id included in the response from Files::upload
},
"list": [
{
"topics_id": 1,
// ...
"file_field": { "file_nm": "File.png" } // File name in the zip file
},
{
"topics_id": 2,
// ...
"file_field": { "file_nm": "PdfFile.pdf" }
},
{
"subject": "New Content",
// ...
"file_field": { "file_nm": "Image.png" }
}
]
}
- Please replace
file_field
to your own extension item's ID (ext_X) or slug.
Uploading with custom processing
If you call bulk_upsert from custom processing, you cannot use the Files::upload API, so you need to upload the file using a file manipulation plugin.
Here is an example of uploading the assets.zip
file placed in the /files/ltd
directory of the file manager with custom processing.
{rcms_hash var='temp_name' data='bulk_upsert_assets' key=$smarty.now|strval}
{assign var='temp_assets_path' value="/files/temp/`$temp_name`.zip"}
{put_file path=$temp_assets_path files_path="/files/ltd/assets.zip"}
{assign_array var='body' values=''}
{* assets_file *}
{assign_array var='body.assets_file' values=''}
{assign var='body.assets_file.file_id' value=$temp_assets_path|trim:'/'}
{* list *}
{assign_array var='body.list' values=''}
{assign_array var='content' values=''}
{assign var='content.topics_id' value=1}
{assign_array var='content.file_field' values=''}
{assign var='content.file_field.file_nm' value='File.png'}
{assign var='body.list.' value=$content}
{* POST Topics::bulk_upsert *}
{api_internal var='response' method='POST' endpoint='/rcms-api/1/topics/bulk_upsert' queries=$body member_id=$smarty.session.member_id}
- Replace the
value=1
part with the content ID you want to update. - Please replace
file_field
to your own extension item's ID (ext_X) or slug. - Modify
File.png
to the name of the uploaded file. - Replace
/rcms-api/1/topics/bulk_upsert
with your own endpoint. It should be a secure API with dynamic access tokens set up.
Reference: Smarty Plugin
Reference: Can I call Kuroco's API using custom function?
Related Documents
Support
If you have any other questions, please contact us or check out Our Slack Community.