Baidu AI Cloud
中国站

百度智能云

Object Storage

Upload Data to BOSCDN by CDN Dynamic Acceleration

Overview

This article focuses on how to use the dynamic acceleration feature of CDN to improve the transmission speed and stability of the client data upload to BOS.

Application Scenarios

BOS and CDN jointly launched the dynamic acceleration feature of data upload, primarily to meet the acceleration needs of users in the scenarios of uploading data via BOS. This feature takes full advantage of the industry-leading architecture advantages of Baidu Cloud CDN. Through upload link optimization, private protocol, real-time adaptation, and intelligent path switching, it greatly reduces the time for data uplink transmission and increases the rate of uploading files to BOS.

The CDN dynamic acceleration feature of BOS can meet the needs of customers for acceleration of a variety of uplink transmission application scenarios of data such as audio, video, and photo:

  • Common file upload acceleration scenarios
  • Small file upload scenarios
  • Remote file uploading scenario
  • File upload scenarios in weak network environments such as network congestion
  • Cross-network and cross-operator file upload scenarios

Advantages

Uploading data to BOS through CDN dynamical acceleration has the following advantages:

  • Through Baidu’s high-quality CDN nodes around the world, it solves the problems of slow upload to BOS, data packet loss, and instability of service caused by factors such as cross-operator, cross-border, network instability, etc., and provides users with fast, reliable and smooth data upload experience;
  • Baidu self-developed comprehensive optimization and acceleration plan for the entire process of file uplink transmission can, through core technologies, such as link optimization, protocol layer optimization, routing optimization, transmission optimization, and intelligent path switching, achieve the central node multi-line access, real-time detection and intelligent selection of forward-to-origin links, and get the optimal path for transmission to significantly enhance the upload acceleration effect;
  • CDN dynamic acceleration upload supports dynamic HTTPS request acceleration, fast transmission of encrypted data, and has the ability to resist DDoS and CC attacks to ensure the availability and security of the data upload process.

Use Mode

Taking users uploading binary files, such as videos and photos, for example, the storage solution of using CDN to dynamically accelerate the upload of data to BOS can optimize the upload process, and improve the upload speed and upload experience with a limited increase in cost. The specific solution and steps are as follows:

  1. Log in to the console and open the Bucket release management page that needs to be enabled for uplink acceleration, enable the official CDN acceleration of the Bucket, and enable the CDN dynamic acceleration feature. Afterwards, CDN dynamic acceleration costs will be incurred.
  2. For the detailed enabling method, please refer to Console Operation Guide-Data Release-CDN Uplink Acceleration.

Use CDN to accelerate data upload

BOS provides a variety of file upload solutions such as console upload, API or SDK upload, and BOS CLI upload. For the CDN accelerated upload feature, you can choose Upload by API or SDK.

Accelerate file upload via API

When uploading data to BOS via PutObject Interface of BOS API, you only need to replace the HOST of API request with the CDN acceleration domain name (that is, your customized acceleration domain name or official CDN accelerated domain name +'/'+'file name'), that is, upload is accelerated through CDN. E.g.: Original upload request:

PUT /<ObjectName> HTTP/1.1 
Host: <BucketName>.bj.bcebos.com 
Date: <Date> 
Authorization: <AuthorizationString> 
Content-Type: text/plain
Content-Length: <Content_Length> 

CDN accelerated upload request:

PUT /<ObjectName> HTTP/1.1 
Host: <BucketName>.cdn.bcebos.com 
Date: <Date> 
Authorization: <AuthorizationString> 
Content-Type: text/plain
Content-Length: <Content_Length> 

Accelerate file upload via SDK

SDK configuration of different language versions uses CDN to accelerate upload in different ways. In this case, uploading a file through Go SDK is taken as an example. For SDK usage in other languages, please refer to the corresponding SDK documentation.

  1. The SDK configures the accelerated domain name for CDN accelerated upload as ENDPOINT. For example, cdn-test.cdn.bcebos.com is the CDN accelerated domain name corresponding to the bucket of cdn-test obtained after enabling the CDN accelerated upload feature on the console. The code is as follows:
AK, SK := "xxx", "yyy" 
ENDPOINT := "cdn-test.cdn.bcebos.com" 
bosClient, _ := bos.NewClient(AK, SK, ENDPOINT) 
  1. Configure the switch to enable the CDN acceleration upload. It should be noted that the CnameEnabled configuration item indicates whether to upload files to BOS via a custom domain name. If your ENDPOINT is an official acceleration domain name with the suffix of .cdn.bcebs.com, you don’t need to configure this switch; if your ENDPOINT is a custom accelerated domain name, you must set CnameEnabled to true to take effect.
bosClient.Config.CnameEnabled = true 
  1. Use the configured bosClient to upload files to experience CDN acceleration. After uploading, check whether the files are uploaded successfully.
bosClient.PutObjectFromFile(bucketName, objectName, filePath, nil) 

Configure retry alternate domain name

On the basis of supporting the configuration of CDN domain name acceleration to upload files to BOS, taking into account the stability of the upload process, the SDK further supports the mechanism of retrying the alternate domain name when the primary domain name upload fails. The usage is as follows:

// If uploading files via ENDPOINT fails, the SDK will automatically retry the BackupEndpoint domain name 
bosClient.Config.BackupEndpoint = "cdn-test.bj.bcebos.com" 
Previous
Client Encryption Practice
Next
Use HTTPDNS Service Through Android SDK