Upload files using the OSS API
To upload network files, automate uploads, or perform batch migrations, call Intelligent Media Services (IMS) APIs to obtain an upload URL and credential, and then use native Object Storage Service (OSS) APIs to complete the upload.
Prerequisites
-
You are familiar with the supported file formats. For more information, see Supported file formats.
-
You have activated Object Storage Service (OSS). For more information, see Activate OSS.
Background information
Before you upload a media asset by using an OSS API, you must obtain an upload URL and credential from IMS. The upload URL specifies the storage address in OSS, and the credential authorizes the upload. IMS issues both the URL and the credential to ensure security and prevent malicious uploads. When IMS issues the upload URL and credential, it also automatically creates a media asset ID that you can use for media asset lifecycle management or ApsaraVideo Media Processing.
Notes
-
The maximum size for a single audio or video file is 5 GB.
-
File extensions are not case-sensitive during upload. If an extension is not supported, the upload fails because the file format does not match the upload credential.
Step 1: Obtain an upload URL and credential
Call the CreateUploadMedia operation to obtain the upload URL and credential for a media asset. You can integrate the server-side SDK (recommended) or build your own HTTP(S) request. For more information, see RPC mechanism.
-
Each upload URL and credential can be used for only one media asset. Do not use them for multiple assets to avoid overwriting files.
-
If you request an upload URL and credential for the same media asset multiple times, a different URL and credential are returned for each request.
-
Upload URLs are automatically assigned by Intelligent Media Services. Custom URLs are not supported.
-
An upload credential is valid for 3000 seconds. For large video files, the credential may expire during the upload. If it expires, call the RefreshUploadMedia operation to refresh it. The new credential is also valid for 3000 seconds, and the upload URL remains unchanged.
-
For smaller files, such as images and auxiliary media assets such as caption and font files, you must obtain a new credential if the current one expires.
Step 2: Call an OSS API to upload the media asset
Base64-decode the upload URL and credential. Then, call an OSS upload API to upload the media asset. For more information, see Common HTTP headers and Upload files to OSS.