Upload by URL

Updated at:

Upload media assets by URL by calling an OpenAPI operation through a server-side SDK.

Usage notes

To configure environment variables, see Configure environment variables in Linux, macOS, and Windows.

Sample code

To debug online, use the Alibaba Cloud OpenAPI Developer Portal.

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 for an Alibaba Cloud account has permissions to access all APIs. Use a Resource Access Management (RAM) user for API calls and routine O&M.
    // This example shows how to store an AccessKey ID and an AccessKey secret in environment variables. For more information, see https://help.aliyun.com/document_detail/378661.html.
    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 the AccessKey ID and AccessKey secret, use the following code. Do not hard-code the AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey leak and compromise the security of all resources in your account.
    // config := new(openapi.Config)
    // config.SetAccessKeyId("<accessKeyId>").
    //     SetAccessKeySecret("<accessKeySecret>").
    //     SetRegionId("<regionId>").
    //     SetEndpoint("<endpoint>")
    // iceClient, _err := ice.NewClient(config)

    if _err != nil {
      panic(_err)
    }

    // Submit the URL upload task.
    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