File Management

Last Updated on : 2024-06-18 09:35:30download

File management allows connected devices to upload and download general files to and from the storage space on the Tuya Developer Platform over MQTT.

This topic describes the topics and data format for file management.

  • The storage space provides device-based access isolation, protecting data from unauthorized access.
  • The download URL is valid for a limited time. After it expires, the device should request the download URL again.

Upload a file

Device sends messages

The device requests a presigned URL for upload and then uploads a file using the returned presigned URL.

A file should not exceed 16 MB in size.

Topic: tylink/${deviceId}/ext/file/upload/request

{
    "msgId":"45lkj3551234***",
  	"time":1626197189638,
	"data":{
        "bizType":"FILE",
        "fileName":"apple.png"
    }
}

Parameter description

Parameter Type Description Required Remark
${deviceId} String Device ID Yes If this is a sub-device, the deviceId should be the ID of the sub-device.
version String Protocol version No The protocol version defaults to 1.0, which is the only valid value currently.
msgId String Message ID Yes A string up to 32 characters in length. A message ID is used to correlate responses and requests.
time Number Message timestamp Yes The Unix timestamp when a message is sent, in seconds (10-digit value) or milliseconds (13-digit value).
data Object Time service parameters Yes Get the time service parameters.
data.bizType String Business type Yes The supported file types. The default value is FILE.
data.fileName String File name Yes For example, apple.png.

Device receives messages

The device receives a presigned URL for upload.

Topic: tylink/${deviceId}/ext/file/upload/response

{
    "msgId":"45lkj3551234***",
  	"time":1626197189638,
	"data":{
        "bizType":"FILE",
        "url":"https://tuya-temp-fileupload-1254153901.cos.ap-shanghai.myqcloud.com/iot-platform-tmp/bay1617694933431vh5n/1631015173bbb14756aa2.png?sign=q-sign-algorithm%3Dsha1%26q-ak%3DAKIDopcCYgw0qRoyV5qfKjvg2pPkqESnb5zI%26q-sign-time%3D1631015173%3B1631018773%26q-key-time%3D1631015173%3B1631018773%26q-header-list%3D%26q-url-param-list%3D%26q-signature%3D4670e7d3cf500f9210a0f2d5bc9e98d6e*****a6"
    }
}

Parameter description

Parameter Type Description Required Remark
${deviceId} String Device ID Yes If this is a sub-device, the deviceId should be the ID of the sub-device.
version String Protocol version No The protocol version defaults to 1.0, which is the only valid value currently.
msgId String Message ID Yes A string up to 32 characters in length. A message ID is used to correlate responses and requests.
time Number Message timestamp Yes The Unix timestamp when a message is sent, in seconds (10-digit value) or milliseconds (13-digit value).
data Object Time service parameters Yes Get the time service parameters.
data.bizType String Business type Yes The supported file types. The default value is FILE.
data.url String The presigned URL to upload a file. Yes The presigned URL to upload a file to the cloud.

Download a file

Device sends messages

The device requests the URL to download the specified file from the cloud.

Topic: tylink/${deviceId}/ext/file/download/request

{
    "msgId":"45lkj3551234***",
  	"time":1626197189638,
	"data":{
        "bizType":"FILE",
        "fileName":"apple.png"
    }
}

Parameter description

Parameter Type Description Required Remark
${deviceId} String Device ID Yes If this is a sub-device, the deviceId should be the ID of the sub-device.
version String Protocol version No The protocol version defaults to 1.0, which is the only valid value currently.
msgId String Message ID Yes A string up to 32 characters in length. A message ID is used to correlate responses and requests.
time Number Message timestamp Yes The Unix timestamp when a message is sent, in seconds (10-digit value) or milliseconds (13-digit value).
data Object Time service parameters Yes Get the time service parameters.
data.bizType String Business type Yes The supported file types. The default value is FILE.
data.fileName String File name Yes For example, apple.png.

Device receives messages

The device receives the URL to download the specified file.

Topic: tylink/${deviceId}/ext/file/download/response

{
    "msgId":"45lkj3551234***",
  	"time":1626197189638,
	"data":{
        "bizType":"FILE",
        "fileName": "apple.png",
        "url":"https://tuya-temp-fileupload-1254153901.cos.ap-shanghai.myqcloud.com/iot-platform-tmp/bay1617694933431vh5n/1631015173bbb14756aa2.png?sign=q-sign-algorithm%3Dsha1%26q-ak%3DAKIDopcCYgw0qRoyV5qfKjvg2pPkqESnb5zI%26q-sign-time%3D1631015173%3B1631018773%26q-key-time%3D1631015173%3B1631018773%26q-header-list%3D%26q-url-param-list%3D%26q-signature%3D4670e7d3cf500f9210a0f2d5bc9e98d6******a6",
        "expirationMillis": 1656319250000
    }
}

Parameter description

Parameter Type Description Required Remark
${deviceId} String Device ID Yes If this is a sub-device, the deviceId should be the ID of the sub-device.
version String Protocol version No The protocol version defaults to 1.0, which is the only valid value currently.
msgId String Message ID Yes A string up to 32 characters in length. A message ID is used to correlate responses and requests.
time Number Message timestamp Yes The Unix timestamp when a message is sent, in seconds (10-digit value) or milliseconds (13-digit value).
data Object Time service parameters Yes Get the time service parameters.
data.bizType String Business type Yes The supported file types. The default value is FILE.
data.url String The presigned URL to download a file. Yes The presigned URL to download a file. A presigned URL expires after a set timeout, which is specified in the parameter expirationMillis.
data.expirationMillis Long Expiration time of the download URL, in milliseconds Yes The time when the download URL will expire, for example, 1656319250000.