JSON REST API - Upload an Asset
This guide explains how to upload a file, such as an image, into the eMedia Library server using the JSON REST API.
1. Choose the destination folder
Decide where the uploaded file should be saved in the eMedia library server.
Example destination path:
Clients/TK2/TK2024342/2020-6/This path will be sent as the sourcepath.
__________________________________________________________________________________
2. Create the JSON file
Create a file named source.json.
Inside it, add the destination path:
{
"sourcepath": "Clients/TK2/TK2024342/2020-6/"
}The sourcepath tells eMedia Library server where to save the uploaded asset.
__________________________________________________________________________________
3. Prepare the file you want to upload
Make sure the file you want to upload is available in the same folder where you are running the command.
Example file:
sample.jpg__________________________________________________________________________________
Step 4: Send the upload request
Use the following curl command:
curl -X POST "http://entermediadb.org/assets/mediadb/services/module/asset/create" \
-H "Content-Type: multipart/form-data" \
-b "entermedia.keyassets=YOUR_COOKIE_VALUE; JSESSIONID=YOUR_SESSION_ID" \
-F "json=@source.json;type=application/json" \
-F "file=@sample.jpg"Replace the following values:
YOUR_COOKIE_VALUE
YOUR_SESSION_ID
sample.jpgwith your actual cookie and file name.
__________________________________________________________________________________
Step 5: Check the response
If the upload is successful, the API returns HTTP 200 and a response with:
{
"response": {
"status": "ok",
"id": "AXLIZAeT6Khr_XFrhdhk"
}
}The important part is:
"status": "ok"This means the file was uploaded successfully.
__________________________________________________________________________________
Step 6: Save the asset ID
The response includes an asset ID:
"id": "AXLIZAeT6Khr_XFrhdhk"This ID uniquely identifies the uploaded asset in EnterMediaDB.
You may need this ID later to retrieve, update, or reference the asset.
__________________________________________________________________________________
Example successful response
{
"response": {
"status": "ok",
"id": "AXLIZAeT6Khr_XFrhdhk"
},
"data": {
"id": "AXLIZAeT6Khr_XFrhdhk",
"name": "sample.jpg",
"sourcepath": "Clients/TK2/TK2024342/2020-6",
"filesize": "348669"
}
}Request (POST)
Paramaters
sourcepath: Destination path on entermedia server to be saved
Sample request
create file with json: cat source.json { "sourcepath":"Clients/TK2/TK2024342/2020-6/" } curl -H "Content-Type: multipart/form-data" \ --request POST http://entermediadb.org/assets/mediadb/services/module/asset/create \ -b 'entermedia.keyassets=adminmdxxxx; JSESSIONID=xxx' \ --form "json=<source.json;type=application/json" \ --form "file=sample.jpg;type=multipart/form-data"
Response
A successful request returns http 200 and status = "ok".
Sample Response
{ "response": { "status": "ok", "id": "AXLIZAeT6Khr_XFrhdhk" }, "data": { "datatype": { "id": "original", "name": "" }, "id": "AXLIZAeT6Khr_XFrhdhk", "name": "source.gif", "sourcepath": "Clients/TK2/TK2024342/2020-6", "foldersourcepath": "Clients/TK2/TK2024342", "category-exact": [ { "id": "2020-6", "name": "" } ], "isfolder": "true", "category": [ { "id": "AXLIZAdi6Khr_XFrhdhj", "name": "2020-6" }, { "id": "index", "name": "Index" }, { "id": "AXLIZAdK6Khr_XFrhdhi", "name": "TK2024342" }, { "id": "AXLIZAcf6Khr_XFrhdhg", "name": "Clients" }, { "id": "AXLIZAc26Khr_XFrhdhh", "name": "TK2" } ], "assettype": { "id": "photo", "name": "Photos" }, "hasfulltext": "false", "pages": "1", "assetviews": "1", "assetvotes": "0", "colorprofiledescription": "Artifex Software sRGB ICC Profile", "length": "1.0", "duration": "1.2", "bitspersample": "8", "fileformat": { "id": "gif", "name": "GIF" }, "detectedfileformat": "gif", "filesize": "348669", "width": "640", "height": "272", "assetmodificationdate": "2020-06-18T14:10:25", "assetaddeddate": "2020-06-18T13:04:58", "owner": { "id": "admin", "name": "The Administrator" }, "primaryfile": "source.gif", "importstatus": { "id": "needsmetadata", "name": "Pending Metadata" }, "previewstatus": { "id": "0", "name": "Unknown" }, "editstatus": { "id": "1", "name": "Pending" }, "publisheds3": "false", "md5hex": "2c188c23e602ded4885c4c33b67daa42", "duplicate": "false", "duplicatesourcepath": "false", "badge": [ { "id": "asset_duplicatesourcepath_false", "name": "" }, { "id": "asset_assetexpired_false", "name": "" }, { "id": "asset_editstatus_1", "name": "Pending" }, { "id": "asset_haschat_false", "name": "" }, { "id": "asset_deleted_false", "name": "" }, { "id": "asset_emiderror_false", "name": "" }, { "id": "asset_duplicate_false", "name": "" }, { "id": "asset_emidwritten_false", "name": "" }, { "id": "asset_islocked_false", "name": "" } ], "assetexpired": "false", "haschat": "false", "islocked": "false", "deleted": "false", "emidwritten": "false", "emiderror": "false", "xmperror": "false", "missinggenerated": "false", "emrecordstatus": "{recorddeleted=false, mastereditclusterid=test-cluster, lastmodifiedclusterid=test-cluster, recordmodificationdate=Thu Jun 18 14:10:25 EDT 2020, masterrecordmodificationdate=Thu Jun 18 14:10:25 EDT 2020}", "googletagged": "false", "googletranscoded": "false", "pushstatus": { "id": "resend", "name": "Resend" }, "existsonpush": "false", "fromviz": "false" } }