Skip to content

Secured Content Storage Service

Summary

File storage management, upload and retrieval service.

This service is natively used by: - TSDB (timeseries database) service to export archived files. - Device2 (device connectivity) to save file uploaded by devices.

In IoT-connector, content service files are also available for device to be securely downloaded.

Operations

Name Tag Summary
content.clear() Delete all content
content.delete() Delete content
content.deleteMulti() Delete multiple files
content.download() Download URL for content
content.downloadAll() Download all content in this context
content.info() Get information about uploaded content
content.list() List uploaded content
content.upload() Upload URL for content

Events

Name Summary
event Files changed

Configuration parameters

Name Type Description
retention_policy [ object ] Retention policy to delete files
retention_policy[].ttl ^[0-9]+[dy]$ Time to live, should be days or years, eg: 1d, 30d
retention_policy[].name string The name of this policy
retention_policy[].prefix string The prefix to match, if empty, the policy will apply to all

Operations

clear

Description

Deletes all the content for the given context/solution

Responses

  • Returns {[ object ]} for An array of the ids of the deleted content items

    Name Type Description
    id string The id of the content item
  • Returns {object} when An error occurred

    Error information {object}

    Name Type Description
    type string The error message's type
    message string The associated error message

Example

response.message = Content.clear()

delete

Description

Delete the given content item

Arguments

Name Type Description
id string The content unique ID

Responses

  • Returns {object} when The content item was deleted

    The content item id {object}

    Name Type Description
    id string The id of the content item
  • Returns {object} when An error occurred

    Error information {object}

    Name Type Description
    type string The error message's type
    message string The associated error message

Example

response.message = Content.delete({
  id = 'image.png',
})

deleteMulti

Description

Delete multiple files in a solution

Arguments

Name Type Description
body [ string ] The list of files user wants to delete

Responses

  • Returns nil for Files deleted

Example

return Content.deleteMulti({"file1", "file2"})

download

Description

Get the download URL for the specified content item

Arguments

Name Type Description
id string The content unique ID
expires_in ^[0-9]+$ Time duration in seconds or URL validity

Responses

  • Returns {object} when The download URL

    HTTP information for client-side content downloads {object}

    Name Type Description
    id string The id of the content item
    url string The URL to use
    method "GET" The HTTP method to use with this URL
  • Returns {object} when An error occurred

    Error information {object}

    Name Type Description
    type string The error message's type
    message string The associated error message

Example

local filename = "image.png" local file_type = "image/png" local expires_in = 600
local presigned_download = Content.download({
  id = filename,
  type = file_type,
  expires_in = expires_in,
})
-- Create curl download command local curl_command = "curl --output " .. filename .. " "
curl_command = curl_command .. presigned_download.url
return curl_command

downloadAll

Description

Get the download URL list for this context

Arguments

Name Type Description
limit integer Number of files to query
cursor string Indicate the cursor when query files, normally returned by request
expires_in ^[0-9]+$ Time duration in seconds or URL validity

Responses

  • Returns {[ object ]} for The download URL list

    Name Type Description
    id string The id of the content item
    url string The URL to use
    method "GET" The HTTP method to use with this URL
  • Returns {object} when An error occurred

    Error information {object}

    Name Type Description
    type string The error message's type
    message string The associated error message

Example

local opts = {
  cursor = nil, -- specify the file id to start with
  limit = 5,
  expires_in = 600
}
-- This will return download urls for all files return Content.downloadAll(opts)

info

Description

Retrieve metadata and tags associated with uploaded content

Arguments

Name Type Description
id string The content unique ID

Responses

  • Returns {object} when The content info

    A content item's metadata and tags {object}

    Name Type Description
    id string The id of the content item
    tags object Tags and their values for the content item
    tags.* string Tag value
    type string The mime type of the content item
    length integer The content item's length in bytes
    last_modified string(dateTime) Last modified timestamp (formatted as ISO 8601)
  • Returns {object} when An error occurred

    Error information {object}

    Name Type Description
    type string The error message's type
    message string The associated error message

Example

response.message = Content.info({
  id = 'image.png',
})

list

Description

Get the list of content items for the solution

Arguments

Name Type Description
full boolean Return complete content items instead of the id only.
tags string,object(json) Tags Key/(string)values map.
op "AND", "OR" The operation for tags filters logic.
limit integer Approximate number of items to return (Default = 1000).
recursive boolean Return items nested in sub-folders (keys containing '/') (Default = true).
prefix string Only returns items starting with the given prefix.
cursor string Pagination cursor: The last key returned by the previous page.

Responses

  • Returns {[ object ]} for An array of content items

    Name Type Description
    id string The id of the content item
    tags object Tags and their values for the content item
    tags.* string Tag value
    type string The mime type of the content item
    length integer The content item's length in bytes
    last_modified string(dateTime) Last modified timestamp (formatted as ISO 8601)
  • Returns {object} when An error occurred

    Error information {object}

    Name Type Description
    type string The error message's type
    message string The associated error message

Example

response.message = Content.list({
  full = true
})
-- or
response.message = Content.list({
  tags = to_json({mykey = "myvalue"})
})
-- or
response.message = Content.list({
  tags = to_json({mykey = "myvalue", mykey2 = "myvalue2"}),
  op = "OR"
})

upload

Description

Get the upload URL for the specified content item. The content ID will be generated if not supplied, and can be generated using the key, if provided

Arguments

Name Type Description
id string The content unique ID
md5 string The md5 sum of the content to upload
type string The content's type
expires_in ^[0-9]+$ Time duration in seconds or URL validity
tags string,object(json) Tags Key/(string)values map.

Responses

  • Returns {object} when The upload URL

    HTTP information for client-side content uploads {object}

    Name Type Description
    id string The id of the content item
    url string The URL to use
    field string The name of the part containing upload data (must be LAST)
    inputs object Additional parts expected with the upload
    method "POST" The HTTP method to use with this URL
    enctype string The expected form-data encoding to use
  • Returns {object} when An error occurred

    Error information {object}

    Name Type Description
    type string The error message's type
    message string The associated error message

Example

local filename = "image.png" local file_type = "image/png" local expires_in = 600
local presigned_upload = Content.upload({
  id = filename,
  type = file_type,
  expires_in = expires_in,
})
-- Create curl upload command local curl_command = "curl"
for k, v in pairs(presigned_upload.inputs) do
  curl_command = curl_command .. " -F \"" .. k .. "=" .. v .."\""
end -- This assumes the file exist in the same directory as curl is being called from. curl_command = curl_command .. " -F file=@" .. filename .. " " .. presigned_upload.url
return curl_command

Events

event

Description

Notification indicating that files have been changed

Arguments

Name Type Description
ids [ string ] The ids that changed
action (deleted|created) What happened to these files

Example

for _,id in ipairs(event.ids) do
  print("File " .. id .. " was " .. event.action )
end

Last update: December 7, 2021
Back to top