Concept Introduction
Smart Media Hosting (SMH) is a multimedia and file resource managed service based on Cloud Object Storage (COS) and Cloud Infinite (CI). It enables your products and services to use cloud storage capability more conveniently. Before using SMH, it is recommended to learn about some concepts related to this service. Media Library
The media library is the maximum first-level division unit in Smart Media Hosting (SMH). Each media library is entirely independent. Currently, SMH supports creating media type media libraries and file type media libraries. Media type media libraries simulate the concept of an album, while file type media libraries simulate the concept of a hard disk.
Tencent Cloud account login to the console is only required when creating, deleting, or modifying partial settings of a media library. Other operations can be achieved by calling APIs using Smart Media Hosting (SMH) authentication and authorization, no longer requiring a Tencent Cloud account login.
Media Library ID
LibraryId is a unique ID used to identify a media library. It is automatically generated when creating a media library and must be specified in all API calls.
Media Library Key
LibrarySecret is required when calling APIs related to access tokens (for the concept of access tokens, see Access Token). It is used to verify the legitimacy of the caller and is automatically generated when creating a media library. This parameter must be kept secret and cannot be stored or used on the client side—it can only be accessed and used on the server side. Tenant Space
Your products and services may need to dynamically create isolated storage spaces, such as independent columns or culture and entertainment, or for each end user of the product. At this point, you can create a multi-tenant media library to meet the needs. In a multi-tenant media library, you can dynamically create, delete, and modify these isolated tenant spaces through APIs. When managing files in these tenant spaces, you can use access tokens corresponding to the tenant space or high-permission access tokens with no limit to tenant spaces to satisfy different management needs.
When creating a media library, you can choose whether to enable multi-tenant mode. After creation, this property cannot be modified. If not enabled, it operates in single-tenant mode, meaning the entire media library serves as one tenant space.
Album
When creating a media library (single-tenant) or a tenant space via API (multi-tenant), you can specify whether to enable Multi-Album Mode. If enabled, you must first create an album. Media content such as photos and videos can only be uploaded to albums and not directly to the tenant space. Albums do not support multi-level nesting, meaning sub-albums cannot be created within an album. If Multi-Album Mode is not enabled, creating albums is not allowed, and media content can only be uploaded directly to the tenant space.
Whether to enable Multi-Album Mode can only be set when creating a media library or tenant space and cannot be modified after creation. Album names must be unique within the same tenant space.
Access Token
Generated by calling the Generate Access Token API on the server. When generating, the Media Library ID and Media Library Key must be specified. Since the Media Library Key must be kept secret and cannot be stored or used on the client, calling the Generate Access Token API on the client is not allowed.
Except when performing operations on the media library, making API calls related to the access token itself, or calling Read APIs with public read permission on the media library or tenant space, an access token must be provided in other cases to verify access legitimacy.
When generating an access token, you need to specify the granted permissions. You can also specify other parameters. For detailed instructions on generating an access token, see Generate Access Token. User Identity Recognition
SMH does not have the concept of users, nor does it manage user information of your products and services. However, when using an access token to call relevant APIs, you may want to record and identify the operator of related operations, such as the creator of an album or the uploader of media content. Therefore, you can import user identity recognition when generating an access token. This recognition can be the ID or username from your existing user system, or the openid from a WeChat mini program. You can further perform operations manually as needed.
If admin permission is requested when generating an access token and user identity recognition is not specified, you can temporarily assign a user identity recognition when using the access token to call other APIs, so that you can call APIs as a specific user on the server side without the need to regenerate the access token.
Client Identification
If your products and services allow users to log in on multiple devices simultaneously, users may need to manage login status on other devices to prevent identity misappropriation in case of lost devices. At this point, your backend should record all logged-in client device names (or other device identifiers) to help users identify specific devices and delete login status for lost ones. SMH also allows you to specify client identification when generating an access token. When users need to delete login status for a designated client, the corresponding access token can be deleted to protect user identity and data.
Business Architecture Design
SMH was designed to simultaneously support requests initiated by both the server and client. Except for APIs requiring the Media Library Key in the request, other APIs can be securely called directly on the client, improving request efficiency. In addition, SMH focuses on metadata management for file systems, while specific file data is hosted in COS. Therefore, the APIs provided by SMH primarily handle control flow and metadata flow, while data streams reach COS directly. This ensures that clients transmitting data can fully leverage COS's advantages in data transmission.
As shown above, during the file upload stage, the client sends multiple requests to the business backend, SMH, and COS. Only requests to the COS backend involve data streams, while other requests are control flow. Avoiding data streams entering the business backend significantly reduces bandwidth, processing, and cost pressure on the business backend. Since COS offers high bandwidth and low latency, overall performance is improved.
The diagram above only lists some simple scenarios. Based on your product and services requirements, you can freely combine the APIs provided by SMH. If you encounter demand scenarios that SMH cannot meet, you can also contact Online Customer Service to submit your needs. We will assess your requirements as soon as possible. Request Domain
If you use SMH in a mini program, you need to add the related domain to the domain name allowlist.
https://api.tencentsmh.cn
SMH API domain name, add it as a valid domain name for requests.
https://<BucketName-APPID>.cos.<Region>.myqcloud.com
COS domain name, for uploading and downloading files, add it as uploadFile and downloadFile domain names. If your mini program requires requesting files via wx.request, you also need to add this domain as a valid domain name for requests.
BucketName, APPID, and Region are the bucket info bound when creating a media library. You can view them in the COS console, such as https://cloud-album-1250000000.cos.ap-beijing.myqcloud.com.