All Products
Search
Document Center

ApsaraVideo VOD:Batch upload by pulling from URLs

Last Updated:Sep 23, 2025

If your files are accessible through public URLs instead of being stored locally, you can use the ApsaraVideo VOD API to upload them by pulling from the URLs. This method eliminates the need to download files to your local machine before uploading them to ApsaraVideo VOD. It is ideal for offline site migration scenarios.

Features

  • Batch upload by pulling from URLs is an asynchronous task. It is not a real-time operation, and the timeliness of the operation is not guaranteed. After you submit a task, the migration and upload process may take several hours or even days to complete. If timeliness is a high priority, use the upload SDK to upload files or use the OSS SDK to upload files.

  • Each time you submit an upload task for the same media file URL, a new media asset with a new media ID is created in ApsaraVideo VOD.

  • Batch upload by pulling from URLs supports only video and audio formats. For more information, see Supported media formats.

  • If a single file is larger than 20 GB, the upload will fail. Use a different upload method.

Upload through the console

In the console, only the China (Shanghai) region supports uploading audio and video files by Pulling From URLs. This upload method is not supported in other regions.

  1. Log on to the ApsaraVideo VOD console.

  2. In the left-side navigation pane, choose Media Files > Audio/Video.

  3. Click Upload.

    上传音视频

  4. Click Add Media.

    添加音视频

  5. Add the files to upload, configure transcoding, and click Start Upload.

    When you select the URL pull method, enter the file name extension if the URL does not contain one. This increases the success rate of the pull task. A pull task may fail due to network issues or the region where the resource is located. If a task fails, try again after you adjust the network or the service region of the resource.

    URL拉取

Upload using an API

Integrate the ApsaraVideo VOD server-side SDK and call the UploadMediaByURL operation. This operation is supported only in the China (Shanghai), China (Beijing), China (Shenzhen), Singapore, and US (Silicon Valley) regions.

Prerequisites

  • ApsaraVideo VOD is activated. For more information, see Activate ApsaraVideo VOD.

  • The system settings required for the upload, including the storage path in the specified region and the callback settings, are configured. For more information, see Manage storage buckets and Configure callbacks.

  • A RAM user is created and used to access ApsaraVideo VOD. To prevent security risks caused by the leakage of the AccessKey pair of your Alibaba Cloud account, we recommend that you create a RAM user and grant the RAM user the permissions required to access ApsaraVideo VOD. Then, you can use the AccessKey pair of the RAM user to access ApsaraVideo VOD. For more information, see Create and grant permissions to a RAM user.

  • Configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables. For more information, see Configure environment variables in Linux, macOS, and Windows.

    Important
    • The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M.

    • We recommend that you do not hard-code the AccessKey ID and AccessKey secret into your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources in your account is compromised.

  • Optional. A role is created for the RAM user and the role is granted the permissions required to access ApsaraVideo VOD if you want to access ApsaraVideo VOD by using Security Token Service (STS). For more information, see Obtain an STS token.

    Note

    For more information about the scenarios in which STS can be used, see Comparison between credentials and STS.

Sample code

For sample code in other languages, see the SDK Example section of UploadMediaByURL.

V1.0 SDK

Step 1. Install dependencies

<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>aliyun-java-sdk-core</artifactId>
  <version>4.6.1</version>
</dependency>
<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>aliyun-java-sdk-vod</artifactId>
  <version>2.16.32</version>
</dependency>

Step 2. Sample code

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.UploadMediaByURLRequest;
import com.aliyuncs.vod.model.v20170321.UploadMediaByURLResponse;

import java.net.URLEncoder;

/**
 * Sample code for the batch upload by pulling from URLs feature.
 *
 */
public class AudioOrVideoUploadByUrl {

    /** 
     * Reads the AccessKey information.
     */
    public static DefaultAcsClient initVodClient() throws ClientException {
    // The region where ApsaraVideo VOD is activated.
    String regionId = "cn-shanghai"; 
    // The AccessKey of an Alibaba Cloud account has permissions to access all API operations. We recommend that you use the AccessKey of a RAM user for API calls or routine O&M.
    // We strongly recommend that you do not hard-code the AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked, which compromises the security of all resources in your account.
    // This example shows how to use an AccessKey that is obtained from environment variables to verify your identity for API access. Before you run the sample code, configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.
    DefaultProfile profile = DefaultProfile.getProfile(regionId, System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
    DefaultAcsClient client = new DefaultAcsClient(profile);
    return client;
    }

    /**
     * Batch upload by pulling from URLs.
     *
     * @param client The client that sends requests.
     * @return UploadMediaByURLResponse The response to the batch upload request.
     * @throws Exception
     */
    public static UploadMediaByURLResponse uploadMediaByURL(DefaultAcsClient client) throws Exception {
        UploadMediaByURLRequest request = new UploadMediaByURLRequest();
        String url = "http://video_01.mp4";
        String encodeUrl = URLEncoder.encode(url, "UTF-8");
        // The URL of the source video file.
        request.setUploadURLs(encodeUrl);

        // The metadata of the video to upload.
        JSONObject uploadMetadata = new JSONObject();
        // The URL of the source video file to upload. This must match the URL in UploadURLs.
        uploadMetadata.put("SourceUrl", encodeUrl);
        // The video title.
        uploadMetadata.put("Title", "upload by url sample");

        JSONArray uploadMetadataList = new JSONArray();
        uploadMetadataList.add(uploadMetadata);
        request.setUploadMetadatas(uploadMetadataList.toJSONString());

        // UserData: Custom parameter settings. Set this parameter if you need a separate webhook address and pass-through data. This parameter is optional.
        JSONObject userData = new JSONObject();

        // Callback settings in UserData.
        // Message callback settings. If specified, these settings are used. Otherwise, the global event notification settings are used.
        JSONObject messageCallback = new JSONObject();
        // The webhook address.
        messageCallback.put("CallbackURL", "http://192.168.0.0/16");
        // The callback type. Default value: http.
        messageCallback.put("CallbackType", "http");
        userData.put("MessageCallback", messageCallback.toJSONString());

        JSONObject extend = new JSONObject();
        extend.put("MyId", "user-defined-id");
        userData.put("Extend", extend.toJSONString());

        request.setUserData(userData.toJSONString());

        return client.getAcsResponse(request);
    }

    /** 
     * Sample request.
     */
    public static void main(String[] argv) {

        try {
            DefaultAcsClient client = initVodClient();
            UploadMediaByURLResponse response = uploadMediaByURL(client);
            System.out.print("UploadJobs = " + JSON.toJSONString(response.getUploadJobs()) + "\n");
            System.out.print("RequestId = " + response.getRequestId() + "\n");
        } catch (Exception e) {
            System.out.print("ErrorMessage = " + e.getLocalizedMessage());
        }
    }

}

V2.0 SDK

Step 1. Install dependencies

    <dependency>
      <groupId>com.aliyun</groupId>
      <artifactId>vod20170321</artifactId>
      <version>3.6.4</version>
    </dependency>

Step 2. Sample code

Note

For project code, we recommend that you use a more secure method that does not require an AccessKey. For information about how to configure credentials, see Manage access credentials.

package com.aliyun.sample;
import com.aliyun.tea.*;

public class UploadMediaByURL {

    /**
     * description