POST http://yourserver.com/services/update ?id=<asset id> &Filedata=<multipart/form-data encoded file> &metadata=<JSON encoded metadata> &<Elvis metadata field name>=<value> &metadataToReturn=<comma-delimited fields> &nextUrl=<next URL> &keepMetadata=<true> |
What does it do?
This call updates an existing asset in Assets Server with a new file. It can also be used to update metadata.
Tip: The update service behaves almost identical to the create service. The update service has an additional 'id' parameter to specify the asset that should be updated.
Update equals check-in
When an asset is checked-out and FileData is added through the Update API, the asset is checked-in, meaning that all checkedOut fields are reset. In this context, the update action is considered to be the same as a 'check-in' action. This default behavior can be turned off by adding the clearCheckoutState parameter to the update call. For more information, see the Parameters table below.
Log in requirement
Before being able to request information from Assets Server by using a GET request or make changes to the system through a POST request, a log in to Assets Server is required. For information about the available APIs for logging in, see Assets Server REST API - introduction.
POST requests only
This REST API only accepts POST requests, not GET requests. Also, the POST request needs to include a cross-site request forgery (csrf) token.
The csrf token is a unique code which, by including it in the request, also makes the POST request unique and therefore much more secure.
The csrf token is obtained by first logging in to Assets Server through a POST request. The response that is received will include the csrf token which can then be used in subsequent POST requests as a http header:
"X-CSRF-TOKEN: <some_csrf_token>"
For more information including examples, see Assets Server REST API - Performing a POST request with a csrf token.
Parameters
id |
The Assets Server id of the asset to be updated. Required. |
Filedata |
The file to be updated in Assets Server. If you do not specify a file name explicitly using the metadata above, the file name of the uploaded file will be used. The parameter is named "Filedata" because that is the standard name used by flash uploads. This makes it easy to use flash uploaders to upload batches of files to Assets Server. Optional. If omitted, only metadata will be updated. |
metadata |
A JSON encoded object with properties that match Assets Server metadata field names. This metadata will be set on the asset in Assets Server. Optional. You can also use parameters matching Assets Server field names. |
* |
Any parameter matching an Assets Server metadata field name will be used as metadata. This metadata will be set on the asset in Assets Server. Optional. You also use the 'metadata' parameter. |
metadataToReturn |
Comma-delimited list of metadata fields to return in hits. It is good practice to always specify just the metadata fields that you need. metadataToReturn=name,rating,assetCreated Specify "all", or omit to return all available metadata. metadataToReturn=all Leave 'empty' to return only minimal fields metadataToReturn= Optional. Default returns all fields. |
nextUrl |
When specified, the service will send a 301 redirect to this URL when it completes successfully. If you place '${id}' in the URL, it will be replaced with the Assets Server asset id of the updated asset. Optional. If omitted, a simple 200 OK status code will be returned. Note: This must be a relative URL on the same domain as the Assets Server. If you do specify an absolute URL with a domain, only the part of the URL after the domain will be used to redirect to. |
clearCheckoutState |
When true, any checked-out state field is cleared when FileData is included. Fields that are cleared:
Optional. Default true. |
parseMetadataModifications |
Prevents parsing "+" and "-" when set to false. Optional. Default true. |
keepMetadata |
Requires Assets Server 6.107 or higher. When set to true, Assets metadata is maintained and not overridden (with the exception of technical metadata fields such as fileSize; these are always overridden). Fields that are configured to be overridden (by setting keepOnCheckIn=false in the custom-assetinfo.xml file) will be overridden. Optional. Default false. |
Return value
Depending if a nextUrl is specified, this service will either send a 301 redirect, or return an empty 200 OK status.
If the operation fails, an error page with a 500 error status will be returned.
Examples
Upload and replace file
This simple HTML form updates an existing asset:
<form action="http://demo.assets-server.com/services/update"
method="post" enctype="multipart/form-data">
<input type="hidden" name="nextUrl" value="...mypage.html#${id}">
<input type="hidden" name="id" value="5LMAQTW9qfhANn7f6JJVpl">
<label for="file">File </label>
<input type="file" name="Filedata" id="file">
<br><br>
<input type="submit" value="Update">
</form>
Update metadata with form
The following updates the rating of the asset:
<form action="http://demo.assets-server.com/services/update"
method="post">
<input type="hidden" name="nextUrl" value="...mypage.html#${id}">
<input type="hidden" name="id" value="5LMAQTW9qfhANn7f6JJVpl">
<label for="rating">Rating </label>
<input type="text" name="rating" id="rating" value="4">
<label for="status">Status </label>
<select name="status" id="status">
<option>New</option>
<option>Draft</option>
<option>Production</option>
<option>Review</option>
<option>Correction</option>
<option>Final</option>
</select>
<br><br>
<input type="submit" value="Update">
</form>
Update metadata with AJAX and field parameters
Submitting the form has the same effect as the following AJAX call.
update http://demo.assets-server.com/services/update ?id=5LMAQTW9qfhANn7f6JJVpl &rating=4 &status=New |
Update metadata using JSON
Passing metadata as separate parameters is very useful when working with HTML forms. For AJAX calls it can be easier to pass metadata as a JSON encoded string. The following will set the rating to "Rejected" (-1) and will change the status to "Correction".
update
http://demo.assets-server.com/services/update ?id=5LMAQTW9qfhANn7f6JJVpl &metadata={rating: -1, status: "Correction"} |
Clear metadata
To clear the value for a metadata field, pass an empty string for that field.
update
http://demo.assets-server.com/services/update ?id=5LMAQTW9qfhANn7f6JJVpl &rating= &status= |
Add values to existing metadata
Using an update, you can append or remove existing metadata on an asset. For example, you could add a tag to the asset while leaving the current tags intact.
Tip: You need to escape the '+' character with %2B if you use it in URLs. A plain '+' would be interpreted as a space character (as defined in the specification on URL encoding).
The following call will remove the "house" tag from the asset, while at the same time adding the tags "beach", "villa", "sunny". If the asset has the tags "sea", "bay", those would not be removed. If the assets has the tag "villa", it will not get "villa" twice, assets can only have a specific tag once.
update
http://demo.assets-server.com/services/update ?id=5LMAQTW9qfhANn7f6JJVpl &tags=%2Bbeach, -house, %2Bvilla, %2Bsunny |
It is also possible to append text to a single value field using the '+' character or add text around the existing value using {CURRENT}.
update
http://demo.assets-server.com/services/update ?id=5LMAQTW9qfhANn7f6JJVpl &description=%2Bhouse &subject=before{CURRENT}after |
Update metadata and File upload using curl
Update asset with filedata only. For authcred see: Assets Server API - authcred.
curl -F "id= 5LMAQTW9qfhANn7f6JJVpl" -F "Filedata=@/Path/To/File.jpg" http://demo.assets-server.com/services/update?authcred=YWRtaW46Y2hhbmdlbWVub3c=
Update asset with filedata and update metadata
curl -F "id= 5LMAQTW9qfhANn7f6JJVpl" -F "Filedata=@/Path/To/File.jpg" - F "metadata={rating:-1,status:\"Correction\"}" http://demo.assets-server.com/services/update?authcred=YWRtaW46Y2hhbmdlbWVub3c=
Note: If the file name or metadata is quoted by using double-quotes, any double-quote or backslash within the file name or value must be escaped by a backslash.
Comment
Do you have corrections or additional information about this article? Leave a comment! Do you have a question about what is described in this article? Please contact Support.
0 comments
Please sign in to leave a comment.