All Products
Search
Document Center

Intelligent Media Services:Upload media assets by using a URL

Last Updated:Nov 28, 2024

This topic describes the sample code that is used to call an API operation to upload media assets by using a URL.

Usage notes

For more information about how to configure environment variables, see Configure environment variables in Linux, macOS, and Windows.

Sample code

You can use Alibaba Cloud OpenAPI Explorer to perform online debugging.

package main

import (
    "fmt"
    openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
    ice "github.com/alibabacloud-go/ice-20201109/v2/client"
    "github.com/aliyun/credentials-go/credentials"
    "github.com/alibabacloud-go/tea/tea"
)

func main() {

    // An AccessKey pair of an Alibaba Cloud account has access permissions on all API operations. We recommend that you use an AccessKey pair of a RAM user to call API operations or perform routine O&M. 
    // In this example, the AccessKey ID and the AccessKey secret are obtained from the environment variables. For more information, visit https://www.alibabacloud.com/help/en/sdk/developer-reference/v2-manage-go-access-credentials?spm=a2c63.p38356.help-menu-262060.d_1_9_1_2.16c2662axiCNKz. 
    credential, _err := credentials.NewCredential(nil)
    if _err != nil {
      panic(_err)
    }
    iceClient, _err := ice.NewClient(&openapi.Config{
      Credential: credential,
      Endpoint: tea.String("ice.cn-shanghai.aliyuncs.com"),
    })

    // To hard-code your AccessKey ID and AccessKey secret, use the following code. We recommend that you do not save the AccessKey ID and the AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of resources within your account may be compromised. 
    // config := new(openapi.Config)
    // config.SetAccessKeyId("<accessKeyId>").
    //     SetAccessKeySecret("<accessKeySecret>").
    //     SetRegionId("<regionId>").
    //     SetEndpoint("<endpoint>")
    // iceClient, _err := ice.NewClient(config)

    if _err != nil {
      panic(_err)
    }

    // Submit a URL-based upload job. 
    uploadURLs := "https://test.com"
    uploadTargetConfig := "{\"StorageType\":\"oss\",\"StorageLocation\":\"xxx\"}"
    request := &ice.UploadMediaByURLRequest{
        UploadURLs:         &uploadURLs,
        UploadTargetConfig: &uploadTargetConfig,
    }
    response, err := iceClient.UploadMediaByURL(request)
    fmt.Println(response, err)
}

Related API operations

UploadMediaByURL