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.
When using a zip file, you can only update the following items. Updating Vimeo items is not supported.
- Images (uploaded to KurocoFiles)
- Files (uploaded to KurocoFiles)
To update GCS/S3 items, see Updating S3/GCS files using a cloud source folder.
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_fieldto 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=1part with the content ID you want to update. - Please replace
file_fieldto your own extension item's ID (ext_X) or slug. - Modify
File.pngto the name of the uploaded file. - Replace
/rcms-api/1/topics/bulk_upsertwith 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?
Updating S3/GCS files using a cloud source folder
In environments with cloud storage enabled, you can use the cloud_source_dir parameter to reference files directly from cloud storage to update S3/GCS items.
No zip file upload is needed; files are copied from the specified folder in cloud storage.
Preparation
Place the files you want to update in any folder in your cloud storage. Specify a path under the private directory of the file manager.
For example, if you specify upload/assets for cloud_source_dir, the following path will be referenced:
- For S3:
files/a/private/upload/assets/ - For GCS:
files/g/private/upload/assets/
Request example
{
"cloud_source_dir": "upload/assets",
"list": [
{
"topics_id": 1,
// ...
"s3_file_field": { "file_nm": "Document.pdf" } // File name within the cloud_source_dir
},
{
"topics_id": 2,
// ...
"s3_file_field": { "file_nm": "Image.png" }
}
]
}
- Replace
s3_file_fieldwith the ID (ext_X) or slug of your own S3/GCS extension item. - The specified file must exist in the folder specified by
cloud_source_dir. - This feature is only available on sites with cloud storage enabled.
cloud_source_dir can also be used alongside zip file uploads for image/file items. In that case, S3/GCS items will be referenced from cloud_source_dir, while image/file items will be referenced from the assets_file zip.
Related Documents
Support
If you have any other questions, please contact us or check out Our Slack Community.