Release Notes
Announcements
API | Operation Name | Operation Description |
Downloading an Object | Download an object to a local directory. |
{"version": "2.0","statement": [{"action": [//head operation"name/cos:HeadObject",//Downloading operation"name/cos:GetObject",],"effect": "allow","resource": ["qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/doc/*"]}]}
// Bucket name, which consists of bucketname-appid (appid must be included), can be viewed in the COS console. https://console.tencentcloud.com/cos5/bucketlet bucket = "examplebucket-1250000000";//The location identifier of an object in a bucket, also known as the object keylet cosPath = "exampleobject.txt";// Local file download path. If the file does not exist, the sdk will automatically create it.let downliadPath = "Local file path";let getRequest = new GetObjectRequest(bucket, cosPath, downliadPath); let task: DownloadTask = CosXmlBaseService.default().download(getRequest);// Download progress callback task.onProgress = (progress: HttpProgress) => {// progress.complete indicates the currently downloaded size// progress.target is the total size }; task.onResult = {// Download success callback onSuccess: (request, result: CosXmlDownloadTaskResult) => { // todo Logic after successful download },// Download failure callback onFail: (request, error: CosError) => { // todo Logic after download failure } }// Start download task.start();// Pause task// task.pause();// Resume task// task.resume();// Cancel task// task.cancel();
// Anonymous download generates CosXmlBaseService without requiring key inputlet noCredentialService = new CosXmlBaseService( context, new CosXmlServiceConfig("ap-guangzhou") );// Bucket name, which consists of bucketname-appid (appid must be included), can be viewed in the COS console. https://console.tencentcloud.com/cos5/bucketlet bucket = "examplebucket-1250000000";//The location identifier of an object in a bucket, also known as the object keylet cosPath = "exampleobject.txt";// Local file download path. If the file does not exist, the sdk will automatically create it.let downliadPath = "Local file path";let getRequest = new GetObjectRequest(bucket, cosPath, downliadPath); let task: DownloadTask = noCredentialService.download(getRequest);// Start download task.start();
// Bucket name, which consists of bucketname-appid (appid must be included), can be viewed in the COS console. https://console.tencentcloud.com/cos5/bucketlet bucket = "examplebucket-1250000000";//The location identifier of an object in a bucket, also known as the object keylet cosPath = "exampleobject.txt";// Local file download path. If the file does not exist, the sdk will automatically create it.let downliadPath = "Local file path";let request = new GetObjectRequest(bucket, cosPath, downliadPath); try { let result = await CosXmlBaseService.default().getObject(request) // The result includes http headers, etc. } catch (e) { // Exception handling }
Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback