Before you upload media files from clients to an Object Storage Service (OSS) bucket in ApsaraVideo VOD, you must obtain the upload URLs and credentials. This topic describes how to obtain upload URLs and credentials when you use client upload SDKs to upload media files. The upload URLs and credentials are used to initialize upload instances.
Background information
Client upload SDKs support the following authorization methods:
Use an upload URL and credential.
Use a Security Token Service (STS) token.
Upload URLs and credentials are issued by ApsaraVideo VOD to authorize users to upload media files to OSS buckets in ApsaraVideo VOD. Compared with using an STS token, using upload URLs and credentials to upload media files is more beneficial. For more information, see Comparison between credentials and STS. For more information about how to obtain an STS token, see Obtain an STS token.
Upload processes
Client upload SDKs encapsulate the logic of uploading files to OSS buckets. When you upload medial files from clients, the files are directly uploaded to OSS buckets allocated by ApsaraVideo VOD without forwarding by servers. Therefore, the clients must be authenticated. You must deploy an authorization service on your application server to obtain upload URLs and credentials. Client upload SDKs support authorization based on upload credentials and authorization based on STS tokens. We recommend that you use an upload credential. For more information, see Comparison between credentials and STS.
Process of uploading a media file by using an upload URL and an upload credential
The following figure shows the complete process of uploading a media file by using an upload URL and an upload credential. In this example, ApsaraVideo VOD SDK is integrated to obtain the upload URL and credential.
A user deploys an authorization service on an application server, such as ApsaraVideo VOD SDK, to obtain upload URLs and credentials.
A client sends a request to the application server to request an upload URL and an upload credential.
The application server sends a request to ApsaraVideo VOD to request the upload URL and credential.
ApsaraVideo VOD returns the upload URL and credential.
NoteApsaraVideo VOD also generates media IDs, which can be used in media lifecycle management and media processing.
For a video, the media ID is returned in the
VideoId
parameter.For an image, the media ID is returned in the
ImageId
parameter.For an auxiliary media asset, the media ID is returned in the
MediaId
parameter.Properly keep the returned media IDs, which are required in subsequent tasks, such as media asset management, audio and video playback, and media processing.
The application server returns the upload URL and credential to the client.
NoteThe application server does not need to perform Base64 decoding on the upload URL or credential.
The client uses the upload URL and credential to initialize an upload instance.
The client constructs upload parameters to send an upload request.
OSS returns the upload result.
NoteYou can also set callbacks in advance to receive notifications about upload events.
Process of uploading a media file by using an STS token
If you use authorization based on the STS token, you must create a RAM role and grant the RAM role permissions to access ApsaraVideo VOD. For more information, see Use STS to upload videos.
The following figure shows the complete process of uploading a media file by using an STS token.
A user deploys an authorization service on an application server, such as ApsaraVideo VOD SDK, to obtain temporary STS tokens.
A client sends a request to the application server to request an STS token.
The application server sends a request to STS to request the STS token.
STS returns the token.
The application server returns the STS token to the client.
The client uses the STS token to initialize an upload instance.
The client constructs upload parameters to send an upload request.
OSS returns the upload result.
NoteYou can also set callbacks in advance to receive notifications about upload events.
Obtain upload URLs and credentials
We recommend that you call API operations by using the ApsaraVideo VOD SDK to obtain the upload URL and credential. This frees you from complex signature calculations. The process varies based on the programming language that you use.
This topic uses ApsaraVideo VOD SDKs for Java and Python V1.0 as examples. To use ApsaraVideo VOD SDK for other programming languages or ApsaraVideo VOD SDKs V2.0 to obtain upload URLs and credentials, follow the similar logic to call API operations. For more information, see ApsaraVideo VOD SDK.
Language | References |
Java | |
Python |
Use upload URLs and credentials
Each file is bound to an upload URL and an upload credential. Therefore, you must obtain the upload URL and credential issued by the application server from the onUploadStarted callback and specify the upload URL and credential in the upload instance. The specific settings vary based on different clients.
Client | References |
Web | |
Android | |
iOS | |
WeChat mini program |