Object management

BOS

  • Function Release Records
  • Product Announcement
  • S3
    • Overview
    • Compatible Interfaces
    • Compatible Signature Authentication
    • Service domain
    • Compatible Common Headers
    • Compatible Tools
  • Security and compliance
    • Overview
    • Monitoring and Audit
    • Data Disaster Recovery
    • Access control
    • Data protection
    • Data Retention Compliance
    • Data encryption
  • API Reference
    • Interface Specifications
    • Audio and Video Processing Interface
    • Access control
    • Introduction
    • Error code
    • Upload callback
    • Service-Related Interface
      • ListBuckets
      • Quota management
        • DeleteUserQuota
        • PutUserQuota
        • GetUserQuota
    • Image Moderation Service Interface
      • Politician Recognition (Politician)
      • Disgusting Image Recognition (Disgust)
      • API description
      • Watermark and QR Code Recognition (Watermark)
      • Face Detection (Face)
      • Image Quality Recognition (Quality)
      • General Text Recognition (OCR)
      • Pornography Recognition (Antiporn)
      • Public Figure Recognition (Public)
      • Terror Recognition (Terror)
    • Multipart Upload-Related Interface
      • AbortMultipartUpload
      • ListMultipartUploads
      • ListParts
      • User guide
      • UploadPart
      • InitiateMultipartUpload
      • UploadPartCopy
      • CompleteMultipartUpload
    • Bucket-Related Interface
      • Original image protection
        • PutBucketCopyrightProtection
        • GetCopyrightProtection
        • DeleteCopyrightProtection
      • Tag Management
        • PutBucketTagging
        • DeleteBucketTagging
        • GetBucketTagging
      • Quota management
        • PutBucketQuota
        • GetBucketQuota
        • DeleteBucketQuota
      • Data encryption
        • GetBucketEncryption
        • DeleteBucketEncryption
        • PutBucketEncryption
      • Event notification
        • PostResult
        • DeleteNotification
        • PostEvent
        • GetNotification
        • PutNotification
      • Recycle bin
        • DeleteBucketTrash
        • GetBucketTrash
        • PutBucketTrash
      • Data synchronization
        • GetBucketReplicationProgress
        • ListBucketReplication
        • GetBucketReplication
        • PutBucketReplication
        • DeleteBucketReplication
      • Cross-Origin Access
        • GetBucketCors
        • PutBucketCors
        • DeleteBucketCors
      • Mirror back-to-origin
        • PutBucketMirroring
        • DeleteBuketMirroring
        • GetBucketMirroring
      • Basic Operations
        • GetBucketLocation
        • HeadBucket
        • PutBucketStorageclass
        • PutBucket
        • GetBucketStorageClass
        • DeleteBucket
      • Lifecycle
        • DeleteBucketLifecycle
        • GetBucketLifecycle
        • PutBucketLifecycle
      • Permission control
        • PutBucketAcl
        • GetBucketAcl
      • Compliance retention
        • ExtendBucketObjectLock
        • DeleteBucketObjectLock
        • CompleteBucketObjectLock
        • InitBucketObjectLock
        • GetBucketObjectLock
      • Bucket inventory
        • GetBucketInventory
        • ListBucketInventory
        • DeleteBucketInventory
        • PutBucketInventory
      • Requester Pays
        • GetBucketRequestPayment
        • PutBucketRequestPayment
      • Static Website
        • PutBucketStaticWebsite
        • DeleteBucketStaticWebsite
        • GetBucketStaticWebsite
      • Versioning
        • PutBucketVersioning
        • GetBucketVersioning
      • Logging
        • DeleteBucketLogging
        • GetBucketLogging
        • PutBucketLogging
    • Object-Related Interface
      • Object Tag
        • PutObjectTagging
        • GetObjectTagging
        • DeleteObjectTagging
      • Basic Operations
        • CopyObject
        • ListObjects
        • FetchObject
        • GetObjectMeta
        • PostObject
        • listObjectVersions
        • DeleteObject
        • PutObject
        • AppendObject
        • DeleteMultipleObjects
        • RestoreObject
        • GetObject
        • OPTIONSObject
      • Soft links
        • GetSymlink
        • PutSymlink
      • Permission control
        • GetObjectAcl
        • PutObjectAcl
        • DeleteObjectAcl
      • Select scanning
        • SelectObject
  • Console Operation Guide
    • Hierarchical Namespace Bucket Operation Instructions
    • Configuring BOS Multi-User Access Control
    • Image Service
    • Operation preparation
    • Favorite Path
    • Quota management
    • Linkage with Baidu Netdisk sharing
    • Online data import
    • Statistics and monitoring
    • Intelligent Business Analysis
    • Event Notification and Data Processing
    • View and export usage data
    • Image Review Service
    • Automatic file decompression
    • Data Publishing
      • Data Publishing Introduction
      • Global Acceleration
      • Creating a Bucket Custom Domain Name
      • Viewing Bucket Official Domain Name
      • Configure Cache Management
      • Enabling CDN Official Acceleration Domain Name
      • Configuring CDN Upload Acceleration
    • Global Settings
      • VPC Access Control
    • Managing Bucket
      • Set static website hosting
      • Setting Up Log Query
      • Set referer allow list
      • Create bucket
      • Set cross-origin access
      • Set bucket trash
      • Set mirror back-to-origin
      • Set access logs
      • Set server-side encryption
      • Set storage inventory
      • Managing Bucket Tag
      • Querying Bucket
      • Data access trend analysis
      • Bucket quota management
      • Set compliance retention
      • Bucket overview
      • Set data synchronization
      • Setting Up Versioning
      • Requester Pays
      • Delete bucket
      • Managing Lifecycle
        • Overview
        • Configure intelligent tiering
        • Configuring Basic Lifecycle Management
        • Basic Lifecycle Management Usage Instructions
          • Lifecycle Rule Based on Last Accessed Time
          • Lifecycle Rule Based on Last Modified Time
      • Set bucket read-write permissions
        • Permission Introduction
        • Set bucket read-write permissions
    • Manage object
      • Setting Symlink
      • Select scanning
      • Setting Meta Information
      • Share files - get file URLs
      • Parts management
      • Folder sharing
      • Restore Archived Files
      • Delete file
      • Copy and move files
      • Delete folders in batches
      • Batch Managing Object
      • Folder statistics
      • Renamed files
      • Convert file storage class
      • Set file permissions
      • Download file
      • Querying Object
      • Upload files
      • Managing Folder
      • Object Tag
  • Managing Bucket
    • Set static website hosting
    • Set referer allow list
    • Create bucket
    • Set bucket trash
    • Set mirror back-to-origin
    • Set access logs
    • Set server-side encryption
    • Set storage inventory
    • Managing Bucket Tag
    • Bucket quota management
    • Set compliance retention
    • Bucket overview
    • Set data synchronization
    • Requester Pays
    • Delete bucket
    • _Archive
      • Set static website hosting
      • Set referer allow list
      • Create bucket
      • Set cross-origin access
      • Set bucket trash
      • Set mirror back-to-origin
      • Set access logs
      • Set server-side encryption
      • Set storage inventory
      • Managing Bucket Tag
      • Querying Bucket
      • Bucket quota management
      • Set compliance retention
      • Bucket overview
      • Set data synchronization
      • Requester Pays
      • Delete bucket
    • Set bucket read-write permissions
      • Permission Introduction
      • Set bucket read-write permissions
      • _Archive
        • Permission Introduction
        • Set bucket read-write permissions
  • Content Review
    • Video Review
    • Image audit
  • Service Level Agreement (SLA)
    • BOS Service Level Agreement SLA (V3_0)
    • Baidu AI Cloud Object Storage (BOS) Trusted Cloud Certification
  • Data processing
    • Image audit
    • Data Processing FAQs
    • Document preview
    • Video frame capture
    • Instant video transcoding
    • Data Processing Introduction
    • Image Processing Terminology Explanation
    • Multimedia cloud processing
    • Get video metadata
    • General Image Settings
      • Original image protection
    • Intelligent Recognition
      • Overview
    • Image Processing Guide V2_0
      • Removing Metadata
      • Image Scaling
      • Image Brightness
      • Getting Image Information
      • Image Blur
      • Usage rules
      • Image Resizing
      • Quality Transformation
      • Format conversion
      • Progressive Display
      • Image Sharpening
      • Grayscale Transformation
      • Image Contrast
      • Image Rotation
        • Normal Rotation
        • Adaptive Rotation
      • Intelligent Processing
        • Intelligent Processing Usage Rules
        • Intelligent Scenarios
          • Lossless magnification
          • Portrait Cartoonization
          • Sky Segmentation
          • Style conversion
          • Black and white coloring
          • Stretch Restoration
          • Object erasure
        • Intelligent Effects
          • Intelligent Contrast
          • Intelligent Sharpness
          • Intelligent defogging
          • Intelligent Color Grading
      • Image Cropping
        • Rounded-corner rectangle cropping
        • Incircle Crop
        • Normal Crop
        • Index Crop
      • Image Watermark
        • Add Image-Text Mixed Watermark
        • Add Text Watermark
        • Add image watermark
    • Image Processing Guide V1_0
      • Image Cropping
      • Getting Image Information
      • Image Thumbnailing
      • Usage rules
      • Quality Transformation
      • Format conversion
      • Watermark
      • Progressive Display
      • Image Rotation
  • Peripheral Tools
    • fsspec-bosfs
    • Peripheral Tools Overview
    • BOS-FTP Tool
    • Download Zone
    • BOS-AlluxioExtension Tool
    • BOS-PC Client
      • FAQs
      • User guide
      • Installation and Login
    • BOS-HDFS Tool
      • Overview
      • Configuration and Usage
      • Big Data Component Usage Guide
        • DataX Reading and Writing BOS
        • Hive Usage Guide
        • Presto Usage Guide
        • Spark Usage Guide
        • Flume Data Storage to BOS
        • Flink Usage Guide
        • Impala Usage Guide
    • BOS-Probe Error Detection Tool
      • Overview
      • Suggestions and Report Viewing
      • Checking Uploads and Downloads via BOSProbe
      • Installing BOSProbe
    • Docker
      • Overview
    • BOS-CMD Command-Line Tool
      • Configure BCECMD Command-Line Completion
      • Install BOSCMD
      • Overview
      • FAQs
      • Use BOS Service via CMD
      • BOS CMD Common Issues
      • BOSCMD Version Change Records
      • Configure BOSCMD
    • BOS-Import Data Cloud Migration Tool
      • Configuration file
      • Deployment methods
      • Overview
      • Version records
      • Exception handling
      • Log
      • Task Progress Recovery
    • BOS-FS Mount Tool
      • Operations and Practices
      • Overview
      • Version Change Records
      • FAQs
      • Install
      • Configuration
    • BOS-API Generation Tool
      • Overview
      • Service-Related Interface
        • List Buckets
        • Quota management
          • Delete User Credit Quota Settings
          • Get User Credit Quota Information
          • Set User Credit Quota
      • Image Moderation Service Interface
        • Image Review Interface
      • How to Call the API
        • Authentication
        • Construct a Request
        • Return a Response
      • Bucket Data Synchronization Related Interfaces
        • Retrieving the Process Status of Data Synchronization for a Specified ID in a Bucket
        • Setting Up Bucket Data Synchronization
        • Deleting the Synchronization Replication Configuration of a Specified ID in a Bucket
        • Listing All Replication Synchronization Rules of a Bucket
        • Retrieving Bucket Data Synchronization Information
      • Bucket-Related Interface
        • Original image protection
          • Disabling Bucket Original Image Protection Configuration
          • Get the original image protection configuration of bucket
          • Enable the original image protection function of bucket
        • Data encryption
          • Check If Encryption Is Enabled for a Bucket
          • Disable Server-Side Encryption (SSE) for a Bucket
          • Enable Encryption for a Bucket
        • Event notification
          • Setting Up Bucket Notification Rules
          • Retrieving Bucket Notification Rules
          • Pushing ImageOcr and ImageClassify Messages
          • Deleting Bucket Notification Rules
          • Pushing Event Messages
        • Recycle bin
          • Retrieving the Activation Status of the Bucket Recycle Bin
          • Disabling Bucket Recycle Bin Functionality
          • Enabling Bucket Recycle Bin Functionality
        • Cross-Origin Access
          • Get Cross-Origin Resource Sharing (CORS) Rules Set on a Specified Bucket
          • Disable Cross-Origin Resource Sharing (CORS) Rule on a Specified Bucket
          • Set a Cross-Origin Resource Sharing (CORS) Rule on a Specified Bucket
        • Basic Operations
          • List Buckets
          • Cross-Origin Query
          • Create a bucket
          • Get the Default Storage Class of a Bucket
          • List Objects in a Bucket
          • Set default bucket storage class
          • Get the Region of a Bucket
          • Check If a Bucket Exists and Whether the Requester Has Permission to Access the Bucket
          • Delete bucket
        • Lifecycle
          • Get Lifecycle Management Rules for a Bucket
          • Delete Lifecycle Management Rules for a Bucket
          • Set Lifecycle for a Bucket
        • Permission control
          • Set bucket access permissions
          • Get Access Permission for a Bucket
        • Compliance retention
          • Retrieving Bucket Compliance Retention Policies
          • Deleting Compliance Retention Policies
          • Locking Bucket Compliance Retention Policies
          • Delaying the Protection Period of Bucket Compliance Retention Policies
          • Initializing Compliance Retention Policies
        • Static Website
          • Set static website hosting
          • Delete Static Website Hosting Information for a Bucket
          • Get Static Website Hosting Information for a Bucket
        • Logging
          • Enable bucket access logs
          • Disable Access Log Configuration for a Bucket
          • Get Access Log Configuration for a Bucket
      • Object-Related Interface
        • Basic Operations
          • Get Meta Information of an Object
          • Restore Archived Files
          • Get an Object
          • Fetch an Object and Store It in a Bucket
          • Delete Multiple Objects
          • Delete Object
        • Soft links
          • Retrieve a symlink
          • Create a symlink
        • Permission control
          • Set access permission for an object
          • Delete Access Permission for an Object
          • Get Access Permission for an Object
        • Select scanning
          • Execute SQL Statement on an Object
    • MoonBox Physical Migration Device
      • MoonBox introduction
      • MoonBox Operation Process
    • BOS Connector for PyTorch
      • Overview
      • Functionality and Usage Instructions
      • Reading and Writing Checkpoints
      • Installing BOS Connector for Pytorch
      • Building a Dataset
      • Configuring BOS Connector for Pytorch
      • Performance test
    • BOS-CLI Command-Line Tool (Old Version)
      • Overview
      • Version Change Records
      • Configure BOSCLI
      • Install BOSCLI
      • Use BOS Service via CLI
    • BOS-Util Batch Operation Tool
      • Overview
      • Version Change Records
      • Install BOS-Util
      • Using BOS Service via BOS-Util
    • Third-party tools
      • rclone
      • S3 Browser
      • MinIO
      • Goofys
      • Other Tools
  • Typical Practices
    • Using BOS as Backend Storage Service for Jfrog Artifactory
    • How to Solve Browser Cross-Origin CORS Issues
    • Using HTTPDNS Service via Android SDK
    • Client-Side Encryption Practice
    • BOS Dedicated Line Back-to-Origin IDC Best Practices
    • Presto Practice Based on BOS
    • Accessing BOS via Dedicated Line-VPN in Hybrid Cloud
    • CDN Dynamic Acceleration Uploading Data to BOS
    • HTTPS Transmission Encryption Practice
    • Using CDN to Accelerate BOS
    • Hotlink Protection
    • AWS Lambda Synchronizing S3 Data to BOS
    • Impala Practice Based on BOS
    • Direct Upload of Web Data to BOS
      • Advanced Chapter I - STS Temporary Authentication
      • Basic Chapter - Directly Uploading Files to BOS in the Browser
      • Advanced Chapter II - Handling Older Versions of IE via the PostObject Interface
      • Principle Chapter III - STS Temporary Authentication
      • Principle Chapter I - Directly Uploading Files to BOS in the Browser
      • Principle Chapter II - Upload large file in parts
    • Data Migration
      • Migrating Data from Third-Party Clouds to BOS
      • Migrating Local Data to BOS
      • Scenario overview
    • Mobile Photo Editing App Practice
      • Overview and Scenario Introduction
      • Code example
      • Solution Practice - Building the Photo Editing App
      • Solution Practice - Using the Photo Editing App
    • Accessing BOS via Python API Request
      • Upload File to Bucket via PUT Request
      • Basics (Must-Read) - Generation of authentication string
      • Download Bucket File to Local via GET Request
  • FAQs
    • Certification and permission management
    • Image Service
    • Security Problems
    • Bucket Domain Name Request Style
    • General Problems
    • Object upload-download and management
    • Data Migration and Backup
    • Billing Problems
    • API & SDK & Tools
    • Common Questions Overview
    • Bucket access and management
    • Analysis and Statistic
    • Performance-related questions
  • Video Zone
    • Accessing BOS Resources via Domain Name
    • Object upload
    • Understanding BOS
    • BOS Tiered Storage
  • Quick Start
    • Create bucket
    • Get Object
    • Upload Object
    • Quick Start Guide
    • Getting Started with BOS
    • Delete Object
    • Delete bucket
  • Product pricing
    • Billing Cases
    • Insufficient Balance and Debt Reminder
    • View Consumption Details
    • Billing FAQs
    • Product price
      • Resource Package Price List
      • Pay-As-You-Go Charge Type
      • Pay-As-You-Go Price List
        • Traffic Price
        • Storage prices
        • Data Processing Price
        • Request Price
      • Resource Package Charge Type
        • Resource Package Deduction Rules
        • Resource Package Overview
      • Resource Package Price List - Deprecated
        • Internet downlink traffic package
        • Infrequent access storage package
        • Back-to-origin traffic package
        • Archive storage package
        • Cold storage package
        • Standard storage package
    • Charge Item Introduction
      • Traffic fees
      • Storage Cost
      • Request fees
      • Data processing fees
      • Charge Item Overview
  • SDK
    • SDK Overview
    • Harmony-SDK
      • Overview
      • Version Change Records
      • Initialization
      • Install the SDK Package
      • Exception handling
      • Log
      • Bucket management
        • Create Bucket
        • Bucket permission control
        • View the region to which a bucket belongs
        • Bucket Storage Class Setting and Query
        • View bucket list
        • Check if bucket exists
        • Delete bucket
      • Object management
        • Object permission control
        • Multipart upload of objects
        • Get Object
        • View the object in the bucket
        • Copy Object
        • Upload Object
        • Delete Object
    • Ruby-SDK
      • Overview
      • Version Change Records
      • Initialization
      • Install the SDK Package
      • SDK Logging
      • Exception handling
      • Bucket management
        • Create Bucket
        • List buckets
        • Overview
        • Bucket permission management
        • View the region to which a bucket belongs
        • Check if bucket exists
        • Delete bucket
      • File management
        • Object permission control
        • Change file storage class
        • Get file download URL
        • Delete file
        • Copy Object
        • Download file
        • Upload files
        • List files in the storage space
        • Get and update file meta information
        • Check if a file exists
    • Python-SDK
      • Overview
      • Version Change Records
      • Initialization
      • FAQs
      • Install the SDK Package
      • Exception handling
      • Log Control
      • Bucket management
        • Bucket cross-origin resource access
        • Create Bucket
        • Bucket Recycle Bin
        • List buckets
        • Overview
        • Bucket Inventory Management
        • Mirror back-to-origin
        • Bucket Lifecycle Management
        • Event notification
        • Set bucket storage class
        • Bucket permission management
        • View the region to which a bucket belongs
        • Close Recycle Bin
        • Logging
        • Data synchronization
        • Get Recycle Bin Activation Information
        • Check if bucket exists
        • User Credit Quota Management
        • Original image protection
        • Delete bucket
      • File management
        • Object permission control
        • Change file storage class
        • Get file download URL
        • Delete file
        • Copy Object
        • Select file
        • Soft links
        • Download file
        • Upload files
        • Restore archived storage class files
        • List files in the storage space
        • Get and update file meta information
        • Check if a file exists
    • JavaScript-SDK
      • Overview
      • Version Change Records
      • Initialization
      • Quota management
      • Bucket management
      • Install SDK
      • Bucket management
        • Data Synchronization Configuration
        • Create Bucket
        • Overview
        • Bucket Logging Management
        • Bucket Lifecycle Management
        • Set bucket storage class
        • Bucket permission management
        • View the region to which a bucket belongs
        • View bucket list
        • Check if bucket exists
        • Delete bucket
      • Object management
        • Multipart upload of objects
        • Get Object
        • View the object in the bucket
        • Copy Object
        • Upload Object
        • Get File URL
        • Delete Object
    • Android-SDK
      • Overview
      • Version Change Records
      • Initialization
      • Install the SDK Package
      • Exception handling
      • Bucket management
      • Log
      • Object management
      • Bucket management
        • Create Bucket
        • Bucket permission control
        • View bucket list
        • Check if bucket exists
        • Delete bucket
      • File management
        • Object permission control
        • Multipart upload of objects
        • Get Object
        • View the object in the bucket
        • Copy Object
        • Upload Object
        • Delete Object
    • Java-SDK
      • Overview
      • Version Change Records
      • Initialization
      • File management
      • FAQs
      • Install the SDK Package
      • SDK Logging
      • Exception handling
      • Data Processing and Usage
      • Bucket management
      • Bucket management
        • Bucket static website hosting
        • Recycle bin
        • Bucket data synchronization
        • Create Bucket
        • List buckets
        • Overview
        • Mirror back-to-origin
        • Set Bucket server-side encryption
        • Set bucket storage class
        • Bucket permission management
        • View the region to which a bucket belongs
        • Tag Management
        • Check if bucket exists
        • Original image protection
        • Delete bucket
      • File management
        • Copy files
        • Object permission control
        • Change file storage class
        • Get file download URL
        • Delete file
        • Get directory capacity overview
        • Select file
        • Download file
        • Upload files
        • Restore archived storage class files
        • List files in the storage space
        • Object Tag
        • Get and update file meta information
        • Check if a file exists
    • IOS-SDK
      • Overview
      • Version Change Records
      • Initialization
      • Install the SDK Package
      • Exception handling
      • Bucket management
      • Log
      • Object management
      • Bucket management
        • Create New Bucket
        • Determine whether the bucket exists and whether there is permission to access it
        • Bucket permission control
        • View bucket list
        • Delete bucket
      • File management
        • Multipart upload of objects
        • Get Object
        • View the object in the bucket
        • Copy Object
        • Upload Object
        • Delete Object
    • GO-SDK
      • Overview
      • Version Change Records
      • Initialization
      • File management
      • Install the SDK Package
      • SDK Logging
      • Data Processing and Usage
      • Bucket management
      • Request management
      • Error handling
    • C-Dotnet-SDK
      • Overview
      • Version Change Records
      • Initialization
      • Install the SDK Package
      • Exception handling
      • Bucket management
      • Object management
    • PHP-SDK
      • Overview
      • Version Change Records
      • Initialization
      • File management
      • Install the SDK Package
      • Exception handling
      • Bucket management
    • C-SDK
      • Overview
      • Version Change Records
      • Initialization
      • Exception handling
      • Install SDK Toolkit
      • Bucket management
        • Create Bucket
        • List Buckets
        • Overview
        • Check If Bucket Exists
        • Delete Bucket
      • File management
        • Copy files
        • Object permission control
        • Change file storage class
        • Delete file
        • Download file
        • Upload files
        • Archive storage
        • Get and Update Metadata Information
        • Get File Download Link
        • List files in the storage space
        • Check if a file exists
    • C++-SDK
      • Overview
      • Version Change Records
      • Initialization
      • Install the SDK Package
      • SDK Logging
      • Exception handling
      • Bucket management
        • Create Bucket
        • List buckets
        • Overview
        • Bucket permission management
        • View the region to which a bucket belongs
        • Check if bucket exists
        • Delete bucket
      • File management
        • Copy files
        • Object permission control
        • Change file storage class
        • Get file download URL
        • Delete file
        • Object Tag Management
        • Download file
        • Upload files
        • Archive storage
        • List files in the storage space
        • Get and update file meta information
        • Check if a file exists
      • Request management
        • Cancel request interruption
  • Product Description
    • Product functions
    • Application scenarios
    • Product advantages
    • Usage restrictions
    • Product introduction
    • Core concepts
    • Tiered Storage Introduction
      • Why Tiered Storage Exists
      • Introduction to storage classes
  • Data Cube
    • Batch processing
    • ZIP packaging and compression
    • Intelligent Data Processing
      • Video processing
        • Video frame capture
        • Instant video transcoding
        • Multimedia cloud processing
        • M3U8 signature
        • Get video metadata
      • Document processing
        • Document preview
      • Image processing
        • Image Processing Introduction
        • Image Processing FAQs
        • Image Processing Terminology Explanation
        • General Image Settings
          • Original image protection
        • Image Processing Guide V2_0
          • Removing Metadata
          • Image Scaling
          • Image Processing Persistence
          • Image Brightness
          • Image Blind Watermark
          • Return Original Image on Failure
          • Getting Image Information
          • Image Blur
          • Usage rules
          • Quality Transformation
          • Format conversion
          • Progressive Display
          • Image Sharpening
          • Grayscale Transformation
          • Image Compression
          • Image Anomaly Detection
          • Image Contrast
          • Image Rotation
            • Normal Rotation
            • Adaptive Rotation
          • Intelligent Processing
            • Intelligent Processing Usage Rules
            • Intelligent Scenarios
              • Lossless magnification
              • Portrait Cartoonization
              • Sky Segmentation
              • Style conversion
              • Black and white coloring
              • Stretch Restoration
              • Object erasure
            • Intelligent Effects
              • Intelligent Contrast
              • Intelligent Sharpness
              • Intelligent defogging
              • Intelligent Color Grading
          • Image Cropping
            • Rounded-corner rectangle cropping
            • Incircle Crop
            • Normal Crop
            • Index Crop
          • Image Watermark
            • Add Image-Text Mixed Watermark
            • Add Text Watermark
            • Add image watermark
        • Image Processing Guide V1_0
          • Image Cropping
          • Getting Image Information
          • Image Thumbnailing
          • Usage rules
          • Quality Transformation
          • Format conversion
          • Watermark
          • Progressive Display
          • Image Rotation
  • Related Agreements
    • Baidu AI Cloud Object Storage (BOS) and Baidu Netdisk Integration Usage Agreement
  • Developer Guide
    • Single-link rate limit
    • Image audit
    • Region and Endpoint
    • Event notification
    • Monitor Service Operations
    • Static website hosting
    • Basic concepts
    • Development Preparation
    • Data Publishing
      • Binding Custom Domain Name
      • CDN Acceleration Publishing
    • Data Disaster Recovery
      • Multi-AZ storage
      • Data synchronization
    • Data Security
      • Set anti-stealing-link
      • Set bucket trash
      • Set server-side encryption
      • Principle of least privilege
      • Permission control
        • Object permission control
        • Bucket permission control
        • IAM primary-IAM user access control
      • Versioning
        • Deletion Mark
        • Versioning Overview
    • Bucket Basic Operations
      • Create bucket
      • Data Publishing
      • Obtaining Bucket Region Information
      • Managing Lifecycle
      • Set access logs
      • Setting Bucket Tag
      • Setting Cross-Origin Resource Sharing (CORS)
      • View bucket list
      • Delete bucket
    • Data lifecycle management
      • Intelligent Business Analysis
    • Data Migration to Cloud
      • Migration from other clouds
      • Local data to cloud
      • Scenario overview
    • Data lake access
      • Hierarchical namespace
      • Metadata Conversion Service
    • Object Basic Operations
      • Managing Files
        • Copy data
        • Select scanning
        • Delete data
        • Obtaining Data Metadata
        • Viewing File List
        • Object Tag
      • Uploading Data
        • Simple upload
        • Append upload
        • Form upload
        • Upload callback
        • Chunking and Resumable Upload
      • Downloading Data
        • Simple Download
        • Resumable download
  • Data Lake Storage
    • Big Data Component Usage Guide
      • HBase Uses BOS as Underlying Storage
      • Kafka Data Storage to BOS
      • Hive Usage Guide
      • Presto Usage Guide
      • Spark Usage Guide
      • Flume Data Storage to BOS
      • Flink Usage Guide
      • Impala Usage Guide
      • Fluentd Collects Data Storage to BOS
      • Logstash Data Storage to BOS
      • Elasticsearch Snapshot Data Storage to BOS
      • Druid Uses BOS as Deep Storage
    • BOS HDFS tool
      • Overview
      • FAQs
      • Configuration and Usage
    • Data Migration and Transfer
      • Migrate Data to Hierarchical Namespace Bucket Using DistCp
      • DataX Read and Write BOS
    • Hierarchical namespace
      • Usage method
      • Service Introduction
      • Convert Normal Bucket to Hierarchical Namespace Bucket
      • Function Support Description
All documents
menu
No results found, please re-enter

BOS

  • Function Release Records
  • Product Announcement
  • S3
    • Overview
    • Compatible Interfaces
    • Compatible Signature Authentication
    • Service domain
    • Compatible Common Headers
    • Compatible Tools
  • Security and compliance
    • Overview
    • Monitoring and Audit
    • Data Disaster Recovery
    • Access control
    • Data protection
    • Data Retention Compliance
    • Data encryption
  • API Reference
    • Interface Specifications
    • Audio and Video Processing Interface
    • Access control
    • Introduction
    • Error code
    • Upload callback
    • Service-Related Interface
      • ListBuckets
      • Quota management
        • DeleteUserQuota
        • PutUserQuota
        • GetUserQuota
    • Image Moderation Service Interface
      • Politician Recognition (Politician)
      • Disgusting Image Recognition (Disgust)
      • API description
      • Watermark and QR Code Recognition (Watermark)
      • Face Detection (Face)
      • Image Quality Recognition (Quality)
      • General Text Recognition (OCR)
      • Pornography Recognition (Antiporn)
      • Public Figure Recognition (Public)
      • Terror Recognition (Terror)
    • Multipart Upload-Related Interface
      • AbortMultipartUpload
      • ListMultipartUploads
      • ListParts
      • User guide
      • UploadPart
      • InitiateMultipartUpload
      • UploadPartCopy
      • CompleteMultipartUpload
    • Bucket-Related Interface
      • Original image protection
        • PutBucketCopyrightProtection
        • GetCopyrightProtection
        • DeleteCopyrightProtection
      • Tag Management
        • PutBucketTagging
        • DeleteBucketTagging
        • GetBucketTagging
      • Quota management
        • PutBucketQuota
        • GetBucketQuota
        • DeleteBucketQuota
      • Data encryption
        • GetBucketEncryption
        • DeleteBucketEncryption
        • PutBucketEncryption
      • Event notification
        • PostResult
        • DeleteNotification
        • PostEvent
        • GetNotification
        • PutNotification
      • Recycle bin
        • DeleteBucketTrash
        • GetBucketTrash
        • PutBucketTrash
      • Data synchronization
        • GetBucketReplicationProgress
        • ListBucketReplication
        • GetBucketReplication
        • PutBucketReplication
        • DeleteBucketReplication
      • Cross-Origin Access
        • GetBucketCors
        • PutBucketCors
        • DeleteBucketCors
      • Mirror back-to-origin
        • PutBucketMirroring
        • DeleteBuketMirroring
        • GetBucketMirroring
      • Basic Operations
        • GetBucketLocation
        • HeadBucket
        • PutBucketStorageclass
        • PutBucket
        • GetBucketStorageClass
        • DeleteBucket
      • Lifecycle
        • DeleteBucketLifecycle
        • GetBucketLifecycle
        • PutBucketLifecycle
      • Permission control
        • PutBucketAcl
        • GetBucketAcl
      • Compliance retention
        • ExtendBucketObjectLock
        • DeleteBucketObjectLock
        • CompleteBucketObjectLock
        • InitBucketObjectLock
        • GetBucketObjectLock
      • Bucket inventory
        • GetBucketInventory
        • ListBucketInventory
        • DeleteBucketInventory
        • PutBucketInventory
      • Requester Pays
        • GetBucketRequestPayment
        • PutBucketRequestPayment
      • Static Website
        • PutBucketStaticWebsite
        • DeleteBucketStaticWebsite
        • GetBucketStaticWebsite
      • Versioning
        • PutBucketVersioning
        • GetBucketVersioning
      • Logging
        • DeleteBucketLogging
        • GetBucketLogging
        • PutBucketLogging
    • Object-Related Interface
      • Object Tag
        • PutObjectTagging
        • GetObjectTagging
        • DeleteObjectTagging
      • Basic Operations
        • CopyObject
        • ListObjects
        • FetchObject
        • GetObjectMeta
        • PostObject
        • listObjectVersions
        • DeleteObject
        • PutObject
        • AppendObject
        • DeleteMultipleObjects
        • RestoreObject
        • GetObject
        • OPTIONSObject
      • Soft links
        • GetSymlink
        • PutSymlink
      • Permission control
        • GetObjectAcl
        • PutObjectAcl
        • DeleteObjectAcl
      • Select scanning
        • SelectObject
  • Console Operation Guide
    • Hierarchical Namespace Bucket Operation Instructions
    • Configuring BOS Multi-User Access Control
    • Image Service
    • Operation preparation
    • Favorite Path
    • Quota management
    • Linkage with Baidu Netdisk sharing
    • Online data import
    • Statistics and monitoring
    • Intelligent Business Analysis
    • Event Notification and Data Processing
    • View and export usage data
    • Image Review Service
    • Automatic file decompression
    • Data Publishing
      • Data Publishing Introduction
      • Global Acceleration
      • Creating a Bucket Custom Domain Name
      • Viewing Bucket Official Domain Name
      • Configure Cache Management
      • Enabling CDN Official Acceleration Domain Name
      • Configuring CDN Upload Acceleration
    • Global Settings
      • VPC Access Control
    • Managing Bucket
      • Set static website hosting
      • Setting Up Log Query
      • Set referer allow list
      • Create bucket
      • Set cross-origin access
      • Set bucket trash
      • Set mirror back-to-origin
      • Set access logs
      • Set server-side encryption
      • Set storage inventory
      • Managing Bucket Tag
      • Querying Bucket
      • Data access trend analysis
      • Bucket quota management
      • Set compliance retention
      • Bucket overview
      • Set data synchronization
      • Setting Up Versioning
      • Requester Pays
      • Delete bucket
      • Managing Lifecycle
        • Overview
        • Configure intelligent tiering
        • Configuring Basic Lifecycle Management
        • Basic Lifecycle Management Usage Instructions
          • Lifecycle Rule Based on Last Accessed Time
          • Lifecycle Rule Based on Last Modified Time
      • Set bucket read-write permissions
        • Permission Introduction
        • Set bucket read-write permissions
    • Manage object
      • Setting Symlink
      • Select scanning
      • Setting Meta Information
      • Share files - get file URLs
      • Parts management
      • Folder sharing
      • Restore Archived Files
      • Delete file
      • Copy and move files
      • Delete folders in batches
      • Batch Managing Object
      • Folder statistics
      • Renamed files
      • Convert file storage class
      • Set file permissions
      • Download file
      • Querying Object
      • Upload files
      • Managing Folder
      • Object Tag
  • Managing Bucket
    • Set static website hosting
    • Set referer allow list
    • Create bucket
    • Set bucket trash
    • Set mirror back-to-origin
    • Set access logs
    • Set server-side encryption
    • Set storage inventory
    • Managing Bucket Tag
    • Bucket quota management
    • Set compliance retention
    • Bucket overview
    • Set data synchronization
    • Requester Pays
    • Delete bucket
    • _Archive
      • Set static website hosting
      • Set referer allow list
      • Create bucket
      • Set cross-origin access
      • Set bucket trash
      • Set mirror back-to-origin
      • Set access logs
      • Set server-side encryption
      • Set storage inventory
      • Managing Bucket Tag
      • Querying Bucket
      • Bucket quota management
      • Set compliance retention
      • Bucket overview
      • Set data synchronization
      • Requester Pays
      • Delete bucket
    • Set bucket read-write permissions
      • Permission Introduction
      • Set bucket read-write permissions
      • _Archive
        • Permission Introduction
        • Set bucket read-write permissions
  • Content Review
    • Video Review
    • Image audit
  • Service Level Agreement (SLA)
    • BOS Service Level Agreement SLA (V3_0)
    • Baidu AI Cloud Object Storage (BOS) Trusted Cloud Certification
  • Data processing
    • Image audit
    • Data Processing FAQs
    • Document preview
    • Video frame capture
    • Instant video transcoding
    • Data Processing Introduction
    • Image Processing Terminology Explanation
    • Multimedia cloud processing
    • Get video metadata
    • General Image Settings
      • Original image protection
    • Intelligent Recognition
      • Overview
    • Image Processing Guide V2_0
      • Removing Metadata
      • Image Scaling
      • Image Brightness
      • Getting Image Information
      • Image Blur
      • Usage rules
      • Image Resizing
      • Quality Transformation
      • Format conversion
      • Progressive Display
      • Image Sharpening
      • Grayscale Transformation
      • Image Contrast
      • Image Rotation
        • Normal Rotation
        • Adaptive Rotation
      • Intelligent Processing
        • Intelligent Processing Usage Rules
        • Intelligent Scenarios
          • Lossless magnification
          • Portrait Cartoonization
          • Sky Segmentation
          • Style conversion
          • Black and white coloring
          • Stretch Restoration
          • Object erasure
        • Intelligent Effects
          • Intelligent Contrast
          • Intelligent Sharpness
          • Intelligent defogging
          • Intelligent Color Grading
      • Image Cropping
        • Rounded-corner rectangle cropping
        • Incircle Crop
        • Normal Crop
        • Index Crop
      • Image Watermark
        • Add Image-Text Mixed Watermark
        • Add Text Watermark
        • Add image watermark
    • Image Processing Guide V1_0
      • Image Cropping
      • Getting Image Information
      • Image Thumbnailing
      • Usage rules
      • Quality Transformation
      • Format conversion
      • Watermark
      • Progressive Display
      • Image Rotation
  • Peripheral Tools
    • fsspec-bosfs
    • Peripheral Tools Overview
    • BOS-FTP Tool
    • Download Zone
    • BOS-AlluxioExtension Tool
    • BOS-PC Client
      • FAQs
      • User guide
      • Installation and Login
    • BOS-HDFS Tool
      • Overview
      • Configuration and Usage
      • Big Data Component Usage Guide
        • DataX Reading and Writing BOS
        • Hive Usage Guide
        • Presto Usage Guide
        • Spark Usage Guide
        • Flume Data Storage to BOS
        • Flink Usage Guide
        • Impala Usage Guide
    • BOS-Probe Error Detection Tool
      • Overview
      • Suggestions and Report Viewing
      • Checking Uploads and Downloads via BOSProbe
      • Installing BOSProbe
    • Docker
      • Overview
    • BOS-CMD Command-Line Tool
      • Configure BCECMD Command-Line Completion
      • Install BOSCMD
      • Overview
      • FAQs
      • Use BOS Service via CMD
      • BOS CMD Common Issues
      • BOSCMD Version Change Records
      • Configure BOSCMD
    • BOS-Import Data Cloud Migration Tool
      • Configuration file
      • Deployment methods
      • Overview
      • Version records
      • Exception handling
      • Log
      • Task Progress Recovery
    • BOS-FS Mount Tool
      • Operations and Practices
      • Overview
      • Version Change Records
      • FAQs
      • Install
      • Configuration
    • BOS-API Generation Tool
      • Overview
      • Service-Related Interface
        • List Buckets
        • Quota management
          • Delete User Credit Quota Settings
          • Get User Credit Quota Information
          • Set User Credit Quota
      • Image Moderation Service Interface
        • Image Review Interface
      • How to Call the API
        • Authentication
        • Construct a Request
        • Return a Response
      • Bucket Data Synchronization Related Interfaces
        • Retrieving the Process Status of Data Synchronization for a Specified ID in a Bucket
        • Setting Up Bucket Data Synchronization
        • Deleting the Synchronization Replication Configuration of a Specified ID in a Bucket
        • Listing All Replication Synchronization Rules of a Bucket
        • Retrieving Bucket Data Synchronization Information
      • Bucket-Related Interface
        • Original image protection
          • Disabling Bucket Original Image Protection Configuration
          • Get the original image protection configuration of bucket
          • Enable the original image protection function of bucket
        • Data encryption
          • Check If Encryption Is Enabled for a Bucket
          • Disable Server-Side Encryption (SSE) for a Bucket
          • Enable Encryption for a Bucket
        • Event notification
          • Setting Up Bucket Notification Rules
          • Retrieving Bucket Notification Rules
          • Pushing ImageOcr and ImageClassify Messages
          • Deleting Bucket Notification Rules
          • Pushing Event Messages
        • Recycle bin
          • Retrieving the Activation Status of the Bucket Recycle Bin
          • Disabling Bucket Recycle Bin Functionality
          • Enabling Bucket Recycle Bin Functionality
        • Cross-Origin Access
          • Get Cross-Origin Resource Sharing (CORS) Rules Set on a Specified Bucket
          • Disable Cross-Origin Resource Sharing (CORS) Rule on a Specified Bucket
          • Set a Cross-Origin Resource Sharing (CORS) Rule on a Specified Bucket
        • Basic Operations
          • List Buckets
          • Cross-Origin Query
          • Create a bucket
          • Get the Default Storage Class of a Bucket
          • List Objects in a Bucket
          • Set default bucket storage class
          • Get the Region of a Bucket
          • Check If a Bucket Exists and Whether the Requester Has Permission to Access the Bucket
          • Delete bucket
        • Lifecycle
          • Get Lifecycle Management Rules for a Bucket
          • Delete Lifecycle Management Rules for a Bucket
          • Set Lifecycle for a Bucket
        • Permission control
          • Set bucket access permissions
          • Get Access Permission for a Bucket
        • Compliance retention
          • Retrieving Bucket Compliance Retention Policies
          • Deleting Compliance Retention Policies
          • Locking Bucket Compliance Retention Policies
          • Delaying the Protection Period of Bucket Compliance Retention Policies
          • Initializing Compliance Retention Policies
        • Static Website
          • Set static website hosting
          • Delete Static Website Hosting Information for a Bucket
          • Get Static Website Hosting Information for a Bucket
        • Logging
          • Enable bucket access logs
          • Disable Access Log Configuration for a Bucket
          • Get Access Log Configuration for a Bucket
      • Object-Related Interface
        • Basic Operations
          • Get Meta Information of an Object
          • Restore Archived Files
          • Get an Object
          • Fetch an Object and Store It in a Bucket
          • Delete Multiple Objects
          • Delete Object
        • Soft links
          • Retrieve a symlink
          • Create a symlink
        • Permission control
          • Set access permission for an object
          • Delete Access Permission for an Object
          • Get Access Permission for an Object
        • Select scanning
          • Execute SQL Statement on an Object
    • MoonBox Physical Migration Device
      • MoonBox introduction
      • MoonBox Operation Process
    • BOS Connector for PyTorch
      • Overview
      • Functionality and Usage Instructions
      • Reading and Writing Checkpoints
      • Installing BOS Connector for Pytorch
      • Building a Dataset
      • Configuring BOS Connector for Pytorch
      • Performance test
    • BOS-CLI Command-Line Tool (Old Version)
      • Overview
      • Version Change Records
      • Configure BOSCLI
      • Install BOSCLI
      • Use BOS Service via CLI
    • BOS-Util Batch Operation Tool
      • Overview
      • Version Change Records
      • Install BOS-Util
      • Using BOS Service via BOS-Util
    • Third-party tools
      • rclone
      • S3 Browser
      • MinIO
      • Goofys
      • Other Tools
  • Typical Practices
    • Using BOS as Backend Storage Service for Jfrog Artifactory
    • How to Solve Browser Cross-Origin CORS Issues
    • Using HTTPDNS Service via Android SDK
    • Client-Side Encryption Practice
    • BOS Dedicated Line Back-to-Origin IDC Best Practices
    • Presto Practice Based on BOS
    • Accessing BOS via Dedicated Line-VPN in Hybrid Cloud
    • CDN Dynamic Acceleration Uploading Data to BOS
    • HTTPS Transmission Encryption Practice
    • Using CDN to Accelerate BOS
    • Hotlink Protection
    • AWS Lambda Synchronizing S3 Data to BOS
    • Impala Practice Based on BOS
    • Direct Upload of Web Data to BOS
      • Advanced Chapter I - STS Temporary Authentication
      • Basic Chapter - Directly Uploading Files to BOS in the Browser
      • Advanced Chapter II - Handling Older Versions of IE via the PostObject Interface
      • Principle Chapter III - STS Temporary Authentication
      • Principle Chapter I - Directly Uploading Files to BOS in the Browser
      • Principle Chapter II - Upload large file in parts
    • Data Migration
      • Migrating Data from Third-Party Clouds to BOS
      • Migrating Local Data to BOS
      • Scenario overview
    • Mobile Photo Editing App Practice
      • Overview and Scenario Introduction
      • Code example
      • Solution Practice - Building the Photo Editing App
      • Solution Practice - Using the Photo Editing App
    • Accessing BOS via Python API Request
      • Upload File to Bucket via PUT Request
      • Basics (Must-Read) - Generation of authentication string
      • Download Bucket File to Local via GET Request
  • FAQs
    • Certification and permission management
    • Image Service
    • Security Problems
    • Bucket Domain Name Request Style
    • General Problems
    • Object upload-download and management
    • Data Migration and Backup
    • Billing Problems
    • API & SDK & Tools
    • Common Questions Overview
    • Bucket access and management
    • Analysis and Statistic
    • Performance-related questions
  • Video Zone
    • Accessing BOS Resources via Domain Name
    • Object upload
    • Understanding BOS
    • BOS Tiered Storage
  • Quick Start
    • Create bucket
    • Get Object
    • Upload Object
    • Quick Start Guide
    • Getting Started with BOS
    • Delete Object
    • Delete bucket
  • Product pricing
    • Billing Cases
    • Insufficient Balance and Debt Reminder
    • View Consumption Details
    • Billing FAQs
    • Product price
      • Resource Package Price List
      • Pay-As-You-Go Charge Type
      • Pay-As-You-Go Price List
        • Traffic Price
        • Storage prices
        • Data Processing Price
        • Request Price
      • Resource Package Charge Type
        • Resource Package Deduction Rules
        • Resource Package Overview
      • Resource Package Price List - Deprecated
        • Internet downlink traffic package
        • Infrequent access storage package
        • Back-to-origin traffic package
        • Archive storage package
        • Cold storage package
        • Standard storage package
    • Charge Item Introduction
      • Traffic fees
      • Storage Cost
      • Request fees
      • Data processing fees
      • Charge Item Overview
  • SDK
    • SDK Overview
    • Harmony-SDK
      • Overview
      • Version Change Records
      • Initialization
      • Install the SDK Package
      • Exception handling
      • Log
      • Bucket management
        • Create Bucket
        • Bucket permission control
        • View the region to which a bucket belongs
        • Bucket Storage Class Setting and Query
        • View bucket list
        • Check if bucket exists
        • Delete bucket
      • Object management
        • Object permission control
        • Multipart upload of objects
        • Get Object
        • View the object in the bucket
        • Copy Object
        • Upload Object
        • Delete Object
    • Ruby-SDK
      • Overview
      • Version Change Records
      • Initialization
      • Install the SDK Package
      • SDK Logging
      • Exception handling
      • Bucket management
        • Create Bucket
        • List buckets
        • Overview
        • Bucket permission management
        • View the region to which a bucket belongs
        • Check if bucket exists
        • Delete bucket
      • File management
        • Object permission control
        • Change file storage class
        • Get file download URL
        • Delete file
        • Copy Object
        • Download file
        • Upload files
        • List files in the storage space
        • Get and update file meta information
        • Check if a file exists
    • Python-SDK
      • Overview
      • Version Change Records
      • Initialization
      • FAQs
      • Install the SDK Package
      • Exception handling
      • Log Control
      • Bucket management
        • Bucket cross-origin resource access
        • Create Bucket
        • Bucket Recycle Bin
        • List buckets
        • Overview
        • Bucket Inventory Management
        • Mirror back-to-origin
        • Bucket Lifecycle Management
        • Event notification
        • Set bucket storage class
        • Bucket permission management
        • View the region to which a bucket belongs
        • Close Recycle Bin
        • Logging
        • Data synchronization
        • Get Recycle Bin Activation Information
        • Check if bucket exists
        • User Credit Quota Management
        • Original image protection
        • Delete bucket
      • File management
        • Object permission control
        • Change file storage class
        • Get file download URL
        • Delete file
        • Copy Object
        • Select file
        • Soft links
        • Download file
        • Upload files
        • Restore archived storage class files
        • List files in the storage space
        • Get and update file meta information
        • Check if a file exists
    • JavaScript-SDK
      • Overview
      • Version Change Records
      • Initialization
      • Quota management
      • Bucket management
      • Install SDK
      • Bucket management
        • Data Synchronization Configuration
        • Create Bucket
        • Overview
        • Bucket Logging Management
        • Bucket Lifecycle Management
        • Set bucket storage class
        • Bucket permission management
        • View the region to which a bucket belongs
        • View bucket list
        • Check if bucket exists
        • Delete bucket
      • Object management
        • Multipart upload of objects
        • Get Object
        • View the object in the bucket
        • Copy Object
        • Upload Object
        • Get File URL
        • Delete Object
    • Android-SDK
      • Overview
      • Version Change Records
      • Initialization
      • Install the SDK Package
      • Exception handling
      • Bucket management
      • Log
      • Object management
      • Bucket management
        • Create Bucket
        • Bucket permission control
        • View bucket list
        • Check if bucket exists
        • Delete bucket
      • File management
        • Object permission control
        • Multipart upload of objects
        • Get Object
        • View the object in the bucket
        • Copy Object
        • Upload Object
        • Delete Object
    • Java-SDK
      • Overview
      • Version Change Records
      • Initialization
      • File management
      • FAQs
      • Install the SDK Package
      • SDK Logging
      • Exception handling
      • Data Processing and Usage
      • Bucket management
      • Bucket management
        • Bucket static website hosting
        • Recycle bin
        • Bucket data synchronization
        • Create Bucket
        • List buckets
        • Overview
        • Mirror back-to-origin
        • Set Bucket server-side encryption
        • Set bucket storage class
        • Bucket permission management
        • View the region to which a bucket belongs
        • Tag Management
        • Check if bucket exists
        • Original image protection
        • Delete bucket
      • File management
        • Copy files
        • Object permission control
        • Change file storage class
        • Get file download URL
        • Delete file
        • Get directory capacity overview
        • Select file
        • Download file
        • Upload files
        • Restore archived storage class files
        • List files in the storage space
        • Object Tag
        • Get and update file meta information
        • Check if a file exists
    • IOS-SDK
      • Overview
      • Version Change Records
      • Initialization
      • Install the SDK Package
      • Exception handling
      • Bucket management
      • Log
      • Object management
      • Bucket management
        • Create New Bucket
        • Determine whether the bucket exists and whether there is permission to access it
        • Bucket permission control
        • View bucket list
        • Delete bucket
      • File management
        • Multipart upload of objects
        • Get Object
        • View the object in the bucket
        • Copy Object
        • Upload Object
        • Delete Object
    • GO-SDK
      • Overview
      • Version Change Records
      • Initialization
      • File management
      • Install the SDK Package
      • SDK Logging
      • Data Processing and Usage
      • Bucket management
      • Request management
      • Error handling
    • C-Dotnet-SDK
      • Overview
      • Version Change Records
      • Initialization
      • Install the SDK Package
      • Exception handling
      • Bucket management
      • Object management
    • PHP-SDK
      • Overview
      • Version Change Records
      • Initialization
      • File management
      • Install the SDK Package
      • Exception handling
      • Bucket management
    • C-SDK
      • Overview
      • Version Change Records
      • Initialization
      • Exception handling
      • Install SDK Toolkit
      • Bucket management
        • Create Bucket
        • List Buckets
        • Overview
        • Check If Bucket Exists
        • Delete Bucket
      • File management
        • Copy files
        • Object permission control
        • Change file storage class
        • Delete file
        • Download file
        • Upload files
        • Archive storage
        • Get and Update Metadata Information
        • Get File Download Link
        • List files in the storage space
        • Check if a file exists
    • C++-SDK
      • Overview
      • Version Change Records
      • Initialization
      • Install the SDK Package
      • SDK Logging
      • Exception handling
      • Bucket management
        • Create Bucket
        • List buckets
        • Overview
        • Bucket permission management
        • View the region to which a bucket belongs
        • Check if bucket exists
        • Delete bucket
      • File management
        • Copy files
        • Object permission control
        • Change file storage class
        • Get file download URL
        • Delete file
        • Object Tag Management
        • Download file
        • Upload files
        • Archive storage
        • List files in the storage space
        • Get and update file meta information
        • Check if a file exists
      • Request management
        • Cancel request interruption
  • Product Description
    • Product functions
    • Application scenarios
    • Product advantages
    • Usage restrictions
    • Product introduction
    • Core concepts
    • Tiered Storage Introduction
      • Why Tiered Storage Exists
      • Introduction to storage classes
  • Data Cube
    • Batch processing
    • ZIP packaging and compression
    • Intelligent Data Processing
      • Video processing
        • Video frame capture
        • Instant video transcoding
        • Multimedia cloud processing
        • M3U8 signature
        • Get video metadata
      • Document processing
        • Document preview
      • Image processing
        • Image Processing Introduction
        • Image Processing FAQs
        • Image Processing Terminology Explanation
        • General Image Settings
          • Original image protection
        • Image Processing Guide V2_0
          • Removing Metadata
          • Image Scaling
          • Image Processing Persistence
          • Image Brightness
          • Image Blind Watermark
          • Return Original Image on Failure
          • Getting Image Information
          • Image Blur
          • Usage rules
          • Quality Transformation
          • Format conversion
          • Progressive Display
          • Image Sharpening
          • Grayscale Transformation
          • Image Compression
          • Image Anomaly Detection
          • Image Contrast
          • Image Rotation
            • Normal Rotation
            • Adaptive Rotation
          • Intelligent Processing
            • Intelligent Processing Usage Rules
            • Intelligent Scenarios
              • Lossless magnification
              • Portrait Cartoonization
              • Sky Segmentation
              • Style conversion
              • Black and white coloring
              • Stretch Restoration
              • Object erasure
            • Intelligent Effects
              • Intelligent Contrast
              • Intelligent Sharpness
              • Intelligent defogging
              • Intelligent Color Grading
          • Image Cropping
            • Rounded-corner rectangle cropping
            • Incircle Crop
            • Normal Crop
            • Index Crop
          • Image Watermark
            • Add Image-Text Mixed Watermark
            • Add Text Watermark
            • Add image watermark
        • Image Processing Guide V1_0
          • Image Cropping
          • Getting Image Information
          • Image Thumbnailing
          • Usage rules
          • Quality Transformation
          • Format conversion
          • Watermark
          • Progressive Display
          • Image Rotation
  • Related Agreements
    • Baidu AI Cloud Object Storage (BOS) and Baidu Netdisk Integration Usage Agreement
  • Developer Guide
    • Single-link rate limit
    • Image audit
    • Region and Endpoint
    • Event notification
    • Monitor Service Operations
    • Static website hosting
    • Basic concepts
    • Development Preparation
    • Data Publishing
      • Binding Custom Domain Name
      • CDN Acceleration Publishing
    • Data Disaster Recovery
      • Multi-AZ storage
      • Data synchronization
    • Data Security
      • Set anti-stealing-link
      • Set bucket trash
      • Set server-side encryption
      • Principle of least privilege
      • Permission control
        • Object permission control
        • Bucket permission control
        • IAM primary-IAM user access control
      • Versioning
        • Deletion Mark
        • Versioning Overview
    • Bucket Basic Operations
      • Create bucket
      • Data Publishing
      • Obtaining Bucket Region Information
      • Managing Lifecycle
      • Set access logs
      • Setting Bucket Tag
      • Setting Cross-Origin Resource Sharing (CORS)
      • View bucket list
      • Delete bucket
    • Data lifecycle management
      • Intelligent Business Analysis
    • Data Migration to Cloud
      • Migration from other clouds
      • Local data to cloud
      • Scenario overview
    • Data lake access
      • Hierarchical namespace
      • Metadata Conversion Service
    • Object Basic Operations
      • Managing Files
        • Copy data
        • Select scanning
        • Delete data
        • Obtaining Data Metadata
        • Viewing File List
        • Object Tag
      • Uploading Data
        • Simple upload
        • Append upload
        • Form upload
        • Upload callback
        • Chunking and Resumable Upload
      • Downloading Data
        • Simple Download
        • Resumable download
  • Data Lake Storage
    • Big Data Component Usage Guide
      • HBase Uses BOS as Underlying Storage
      • Kafka Data Storage to BOS
      • Hive Usage Guide
      • Presto Usage Guide
      • Spark Usage Guide
      • Flume Data Storage to BOS
      • Flink Usage Guide
      • Impala Usage Guide
      • Fluentd Collects Data Storage to BOS
      • Logstash Data Storage to BOS
      • Elasticsearch Snapshot Data Storage to BOS
      • Druid Uses BOS as Deep Storage
    • BOS HDFS tool
      • Overview
      • FAQs
      • Configuration and Usage
    • Data Migration and Transfer
      • Migrate Data to Hierarchical Namespace Bucket Using DistCp
      • DataX Read and Write BOS
    • Hierarchical namespace
      • Usage method
      • Service Introduction
      • Convert Normal Bucket to Hierarchical Namespace Bucket
      • Function Support Description
  • Document center
  • arrow
  • BOS
  • arrow
  • SDK
  • arrow
  • Android-SDK
  • arrow
  • Object management
Table of contents on this page
  • Upload Object
  • Simplest upload
  • Set the Copy attributes of an object
  • Set object's HTTP Header
  • User-defined metadata
  • Upload object in append mode
  • Obtain upload progress
  • Cancellation interface
  • Synchronous callback
  • View the object in the bucket.
  • Simple query
  • Extended query
  • Query simulated folders
  • Get Object
  • Simple object get
  • Obtain object via GetObjectRequest
  • Obtain download progress
  • Download object to a specified path
  • Obtain the storageClass of an object
  • Obtain only ObjectMetadata
  • Get object URL
  • Object permission control
  • Set access permission for an object.
  • View object permissions
  • Delete object permissions
  • Delete Object
  • Copy Object
  • Multipart upload of objects
  • Multipart Upload Scenarios
  • Multipart Upload Process
  • Initialize Multipart Upload
  • Upload parts
  • Complete multipart upload
  • Cancel multipart upload
  • Retrieve unfinished multipart uploads
  • Get all uploaded part information
  • Encapsulate multipart upload

Object management

Updated at:2025-11-03

Upload Object

Simplest upload

  • Basic workflow

    1. Instantiate the BOSClient class.
    2. The BOSClient.putObject() method allows objects to be uploaded in four ways: file, data stream, binary string, and plain string.
    3. For the returned PutObjectResponse instance, call getETag() to get the successfully uploaded ETag.
  • Example code

    Java
    1// Get specified file
    2 File file = new File(<FilePath>);     //Specify the file path
    3 // Upload object as a file
    4PutObjectResponse putObjectFromFileResponse =
    5    client.putObject(<BucketName>, <ObjectKey>, file);
    6 // Obtain data stream
    7InputStream inputStream = new FileInputStream(<FilePath>);
    8 // Upload an object in the form of a data stream
    9PutObjectResponse putObjectResponseFromInputStream =
    10    client.putObject(<BucketName>, <ObjectKey>, inputStream);
    11 // Upload object as binary string
    12PutObjectResponse putObjectResponseFromByte =
    13    client.putObject(<BucketName>, <ObjectKey>, <byte>);
    14 // Upload object in string form
    15PutObjectResponse putObjectResponseFromString =
    16    client.putObject(<BucketName>, <ObjectKey>, <string>);
    17 // Print ETag
    18System.out.println(putObjectFromFileResponse.getETag());
    Plain Text
    1> **Note**: Objects are uploaded to BOS as files, and the putObject function supports uploading objects with a size not exceeding 5GB. After the putObject request is processed successfully, BOS will return the ETag of the object in the Header as the file identifier.
  • Complete example

    Java
    1import java.io.File;
    2import java.io.FileInputStream;
    3import java.io.FileNotFoundException;
    4import java.io.InputStream;
    5import android.app.Activity;
    6import android.os.Bundle;
    7import com.baidubce.BceClientException;
    8import com.baidubce.BceServiceException;
    9import com.baidubce.auth.DefaultBceCredentials;
    10import com.baidubce.development.R;
    11import com.baidubce.services.bos.BosClient;
    12import com.baidubce.services.bos.BosClientConfiguration;
    13import com.baidubce.services.bos.model.PutObjectResponse;
    14​    
    15public class ExampleActivity extends Activity {
    16  private String bucketName = <BucketName>;
    17  private String objectKey = <ObjectKey>;
    18  byte[] b = null;
    19  String str = <PutString>;
    20  @Override
    21  protected void onCreate(Bundle savedInstanceState) {
    22    super.onCreate(savedInstanceState);
    23    setContentView(R.layout.activity_main);
    24    new Thread(new Runnable() {
    25        @Override
    26        public void run() {
    27            try {
    28                BosClientConfiguration config = new BosClientConfiguration();
    29                config.setCredentials(new DefaultBceCredentials(<AccessKeyID>, <SecretAccessKey>));
    30                config.setEndpoint(<EndPoint>);
    31                BosClient client = new BosClient(config);
    32 // Get specified file
    33                File file = new File("/path/to/file.zip");
    34 // Upload object as a file
    35                PutObjectResponse putObjectFromFileResponse = client.putObject(<BucketName>, <ObjectKey>, file);
    36 // Obtain data stream
    37                InputStream inputStream = new FileInputStream("/path/to/test.zip");
    38 // Upload an object in the form of a data stream
    39                PutObjectResponse putObjectResponseFromInputStream = client.putObject(<BucketName>, <ObjectKey>, inputStream);
    40 // Upload object as binary string
    41                PutObjectResponse putObjectResponseFromByte = client.putObject(<BucketName>, <ObjectKey>, b);
    42 // Upload object in string form
    43                PutObjectResponse putObjectResponseFromString = client.putObject(<BucketName>, <ObjectKey>, str);
    44 // Print ETag
    45                System.out.println(putObjectFromFileResponse.getETag());
    46            } catch (BceServiceException e) {
    47                System.out.println("Error ErrorCode: " + e.getErrorCode());
    48                System.out.println("Error RequestId: " + e.getRequestId());
    49                System.out.println("Error StatusCode: " + e.getStatusCode());
    50                System.out.println("Error Message: " + e.getMessage());
    51                System.out.println("Error ErrorType: " + e.getErrorType());
    52            } catch (BceClientException e) {
    53                System.out.println("Error Message: " + e.getMessage());
    54            } catch (FileNotFoundException e) {
    55                // TODO Auto-generated catch block
    56                e.printStackTrace();
    57            }
    58        }
    59    }).start();
    60}}

Set the Copy attributes of an object

The CopyObject API copies an existing object to a new one. During the process, it checks the source object's ETag or modification status to decide whether to proceed with the operation. The detailed parameters are as follows:

Name Types Description Whether required
x-bce-copy-source-if-match String If the ETag value of the source object matches the ETag value provided by the user, the copy operation is performed; otherwise, it fails. No
x-bce-copy-source-if-none-match String If the ETag value of the source object does not match the ETag value provided by the user, the copy operation is performed; otherwise, it fails. No
x-bce-copy-source-if-unmodified-since String If the source object has not been modified since x-bce-copy-source-if-unmodified-since, the copy operation will proceed; otherwise, it will fail. No
x-bce-copy-source-if-modified-since String If the source object has been modified since x-bce-copy-source-if-modified-since, the copy operation will proceed; otherwise, it will fail. No
  • Example code

    Java
    1// Initialize BosClient
    2BosClient client = ...;
    3 // Create CopyObjectRequest object
    4CopyObjectRequest copyObjectRequest = new CopyObjectRequest(srcBucketName, srcKey, destBucketName, destKey);
    5 // Set new Metadata
    6Map<String, String> userMetadata = new HashMap<String, String>();
    7userMetadata.put("<user-meta-key>","<user-meta-value>");
    8ObjectMetadata meta = new ObjectMetadata();
    9meta.setUserMetadata(userMetadata);
    10copyObjectRequest.setNewObjectMetadata(meta);
    11//copy-source-if-match
    12copyObjectRequest.withETag("111111111183bf192b57a4afc76fa632");
    13//copy-source-if-none-match
    14copyObjectRequest.withNoMatchingETagConstraint("111111111183bf192b57a4afc76fa632");
    15Date modifiedSinceConstraint = new Date();    
    16SimpleDateFormat df = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss z", Locale.UK);  
    17df.setTimeZone(new java.util.SimpleTimeZone(0, "GMT"));        
    18String date = df.format(modifiedSinceConstraint);
    19//copy-source-if-modified-since
    20copyObjectRequest.withModifiedSinceConstraint(date);
    21//copy-source-if-unmodified-since
    22copyObjectRequest.withUnmodifiedSinceConstraint(date);
    23 // Copy Object
    24CopyObjectResponse copyObjectResponse = client.copyObject(copyObjectRequest);

Set object's HTTP Header

BOS allows setting Http Headers when uploading an object.

  • Basic workflow

    1. Create an ObjectMetadata instance.
    2. Use methods like setContentLength() and setContentType() to configure Http Headers.
    3. Pass the metadata as a parameter when calling client.putObject().
  • Example code

    Java
    1// Create an instance of the ObjectMetadata class
    2ObjectMetadata meta = new ObjectMetadata();
    3 // Set ContentLength size
    4meta.setContentLength(<Length>);
    5 // Set ContentType
    6meta.setContentType("application/json");
    7client.putObject(<BucketName>, <ObjectKey>, content, meta);
    Plain Text
    1> **Note:** Headers can be set with attributes such as "Cache-Control", "Content-Encoding", "Content-Disposition", and "Expires"
  • Complete example

    Java
    1import java.io.FileInputStream;
    2import java.io.FileNotFoundException;
    3import java.io.InputStream;
    4import android.app.Activity;
    5import android.os.Bundle;
    6import com.baidubce.BceClientException;
    7import com.baidubce.BceServiceException;
    8import com.baidubce.auth.DefaultBceCredentials;
    9import com.baidubce.demo.R;
    10import com.baidubce.services.bos.BosClient;
    11import com.baidubce.services.bos.BosClientConfiguration;
    12import com.baidubce.services.bos.model.ObjectMetadata;
    13import com.baidubce.services.bos.model.PutObjectResponse;
    14public class ExampleActivity extends Activity {
    15private String bucketName = <BucketName>;
    16private String objectKey = <ObjectKey>;
    17@Override
    18protected void onCreate(Bundle savedInstanceState) {
    19    super.onCreate(savedInstanceState);
    20    setContentView(R.layout.activity_main);
    21    new Thread(new Runnable() {
    22        @Override
    23        public void run() {
    24            try {
    25                BosClientConfiguration config = new BosClientConfiguration();
    26                config.setCredentials(new DefaultBceCredentials(<AccessKeyID>, <SecretAccessKey>));
    27                config.setEndpoint(<EndPoint>);
    28                BosClient client = new BosClient(config);
    29 // Obtain data stream
    30                InputStream inputStream = new FileInputStream("/path/to/test.zip");
    31 // Create an instance of the ObjectMetadata class
    32                ObjectMetadata meta = new ObjectMetadata();
    33 // Set ContentLength size
    34                meta.setContentLength(1000);
    35 // Set ContentType
    36                meta.setContentType("application/json");
    37                PutObjectResponse putObjectResponseFromInputStream = client.putObject(bucketName, objectKey, inputStream, meta);
    38 // Print ETag
    39                System.out.println(putObjectResponseFromInputStream.getETag());
    40            } catch (BceServiceException e) {
    41                System.out.println("Error ErrorCode: " + e.getErrorCode());
    42                System.out.println("Error RequestId: " + e.getRequestId());
    43                System.out.println("Error StatusCode: " + e.getStatusCode());
    44                System.out.println("Error Message: " + e.getMessage());
    45                System.out.println("Error ErrorType: " + e.getErrorType());
    46            } catch (BceClientException e) {
    47                System.out.println("Error Message: " + e.getMessage());
    48            } catch (FileNotFoundException e) {
    49                // TODO Auto-generated catch block
    50                e.printStackTrace();
    51            }
    52        }
    53    }).start();
    54}}

User-defined metadata

BOS supports user-defined metadata for object descriptions.

  • Basic workflow

    1. Create an ObjectMetadata instance.
    2. Use the addUserMetadata() method to add custom metadata to the Http Headers.
    3. Pass the metadata as a parameter when calling client.putObject().
  • Example code

    Java
    1// Set the value of custom metadata name to my-data
    2meta.addUserMetadata("name", "my-data");	  
    3 // Upload Object
    4client.putObject(<BucketName>, <ObjectKey>, <Content>, meta);
    Plain Text
    1> **Note:** In the provided example, a user-defined metadata property is created with the key "name" and the value "my-data." This metadata can be retrieved when the object is downloaded. Though multiple such parameters can be added, the combined size of all User Metadata must not exceed 2KB.  
  • Complete example

    Java
    1import java.io.FileInputStream;
    2import java.io.FileNotFoundException;
    3import java.io.InputStream;
    4import android.app.Activity;
    5import android.os.Bundle;
    6import com.baidubce.BceClientException;
    7import com.baidubce.BceServiceException;
    8import com.baidubce.auth.DefaultBceCredentials;
    9import com.baidubce.demo.R;
    10import com.baidubce.services.bos.BosClient;
    11import com.baidubce.services.bos.BosClientConfiguration;
    12import com.baidubce.services.bos.model.ObjectMetadata;
    13import com.baidubce.services.bos.model.PutObjectResponse;
    14public class ExampleActivity extends Activity {
    15private String bucketName = <BucketName>;
    16private String objectKey = <ObjectKey>;
    17@Override
    18protected void onCreate(Bundle savedInstanceState) {
    19    super.onCreate(savedInstanceState);
    20    setContentView(R.layout.activity_main);
    21    new Thread(new Runnable() {
    22        @Override
    23        public void run() {
    24            try {
    25                BosClientConfiguration config = new BosClientConfiguration();
    26                config.setCredentials(new DefaultBceCredentials(<AccessKeyID>, <SecretAccessKey>));
    27                config.setEndpoint(<EndPoint>);
    28                BosClient client = new BosClient(config);
    29 // Obtain data stream
    30                InputStream inputStream = new FileInputStream("/path/to/test.zip");
    31 // Create an instance of the ObjectMetadata class
    32                ObjectMetadata meta = new ObjectMetadata();
    33 // Custom metadata
    34                meta.addUserMetadata("name", "my-data");	    
    35                PutObjectResponse putObjectResponseFromInputStream = client.putObject(<BucketName>, <ObjectKey>, inputStream, meta);
    36 // Print ETag
    37                System.out.println(putObjectResponseFromInputStream.getETag());
    38            } catch (BceServiceException e) {
    39                System.out.println("Error ErrorCode: " + e.getErrorCode());
    40                System.out.println("Error RequestId: " + e.getRequestId());
    41                System.out.println("Error StatusCode: " + e.getStatusCode());
    42                System.out.println("Error Message: " + e.getMessage());
    43                System.out.println("Error ErrorType: " + e.getErrorType());
    44            } catch (BceClientException e) {
    45                System.out.println("Error Message: " + e.getMessage());
    46            } catch (FileNotFoundException e) {
    47                // TODO Auto-generated catch block
    48                e.printStackTrace();
    49            }
    50        }
    51    }).start();
    52}}

Upload object in append mode

BOS provides an AppendObject feature for uploading files in append mode, making it ideal for scenarios like log appending, live streaming, and real-time video uploads. Objects created via AppendObject belong to the Appendable Objects category, allowing additional data to be appended. In contrast, objects uploaded using PutObject are classified as Normal Objects and do not support data appending. An AppendObject has a size limit between 0 and 5GB.

  • Example code

    Java
    1public void AppendObject(BosClient client, String bucketName, String objectKey, byte[] byte1, String string1) {
    2 // Get specified file
    3      File file = new File("/path/to/file.zip");
    4 // Obtain data stream
    5      InputStream inputStream = new FileInputStream("/path/to/test.zip");
    6 // Upload object as a file
    7      AppendObjectResponse appendObjectFromFileResponse = client.appendObject(bucketName, objectKey, file);
    8 // Upload an object in the form of a data stream
    9      AppendObjectResponse appendObjectResponseFromInputStream = client.appendObject(bucketName, objectKey, inputStream);
    10 // Upload object as binary string
    11      AppendObjectResponse appendObjectResponseFromByte = client.appendObject(bucketName, objectKey, byte1);
    12 // Upload object in string form
    13      AppendObjectResponse appendObjectResponseFromString = client.appendObject(bucketName, objectKey, string1);
    14 // Append content to AppendFile
    15      Long nextOffset = appendObjectFromFileResponse.getNextAppendOffset();
    16      AppendObjectRequest request =new AppendObjectRequest(bucketName, objectKey,
    17      RestartableInputStream.wrap(string1.getBytes()));
    18      request.withOffset(nextOffset);
    19      AppendObjectResponse appendResponse = client.appendObject(request);      
    20}

    ​

Obtain upload progress

The Android SDK supports providing real-time upload progress information during the upload. It currently supports four APIs: PutObject, AppendObject, UploadPart and PutSuperObjectFromFile Using the progress upload interface requires constructing the corresponding Request (PutObjectRequest, AppendObjectRequest, UploadPartRequest and PutSuperObjectRequest).

The SDK offers an upload progress callback API that enables you to define operations to execute during uploads, such as updating the UI.

Java
1public interface BceProgressCallback<T extends AbstractBceRequest> {
2 // request is the upload request
3 // currentSize is the current upload size (unit: byte)
4 // totalSize is the total size to be uploaded in this request (unit: byte)
5      void onProgress(T request, long currentSize, long totalSize);
6}
  • PutObject example code:

    Java
    1PutObjectRequest request = new PutObjectRequest(this.bucketName, "test", file);
    2ObjectMetadata objectMetadata = new ObjectMetadata();
    3objectMetadata.setContentType("text/plain");
    4request.setObjectMetadata(objectMetadata);
    5request.setProgressCallback(new BosProgressCallback<PutObjectRequest>() {
    6    @Override
    7    public void onProgress(PutObjectRequest request, long currentSize, long totalSize) {
    8        Log.e(currentSize + "", totalSize + "");
    9    }
    10});
    11String eTag = this.client.putObject(request).getETag();
  • AppendObject example code:

    Java
    1ObjectMetadata objectMetadata = new ObjectMetadata();
    2objectMetadata.setContentType("text/plain");
    3AppendObjectRequest request = new AppendObjectRequest(this.bucketName, "test", file);
    4request.setObjectMetadata(objectMetadata);
    5AppendObjectResponse response = this.client.appendObject(request);
    6Long nextOffset = response.getNextAppendOffset();
    7request.withOffset(nextOffset);
    8request.setProgressCallback(new BosProgressCallback<AppendObjectRequest>() {
    9    @Override
    10    public void onProgress(AppendObjectRequest request, long currentSize, long totalSize) {
    11        Log.e(currentSize + "", totalSize + "");
    12    }
    13});
    14response = this.client.appendObject(request);
  • UploadPart example code:

    Java
    1UploadPartRequest request = new UploadPartRequest().withBucketName(this.bucketName)
    2        .withKey("test").withUploadId(uploadId).withPartNumber(1).withPartSize(8000)
    3        .withInputStream(fis);
    4request.setProgressCallback(new BosProgressCallback<UploadPartRequest>() {
    5    @Override
    6    public void onProgress(UploadPartRequest request, long currentSize, long totalSize) {
    7        Log.e(currentSize + "", totalSize + "");
    8    }
    9});
    10UploadPartResponse response = this.client.uploadPart(request);
  • PutSuperObjectFromFile example code:

    Java
    1PutSuperObjectRequest request = new PutSuperObjectRequest().withBucketName(this.bucketName)
    2        .withKey("test").withPartSize(1024*1024*2L).withFile(file);
    3request.setProgressCallback(new BosProgressCallback<PutSuperObjectRequest>() {
    4    @Override
    5    public void onProgress(PutSuperObjectRequest request, long currentSize, long totalSize) {
    6        Log.e(currentSize + "", totalSize + "");
    7    }
    8});
    9PutSuperObjectResponse response = this.client.putSuperObjectFromFile(request);

    By default, the SDK’s upload progress callback granularity is 2,048 bytes. You can adjust the granularity to better suit your application using the provided methods.

    BosClientConfiguration config=new BosClientConfiguration(); config.setUploadSegmentPart(1024);

Note: This value must be between 1-8192. If outside this range, Android SDK will forcibly set it to 2048.

Cancellation interface

Android SDK supports canceling this request during the request process. The remaining data in the upload request will not be uploaded to BOS. Canceling the operation in the download request will close the connection, and the executing operation will throw Request is canceled! exception.

All BOS operations support cancellation interfaces, but completed requests cannot be canceled, and no exceptions will be thrown for completed operations

Java
1// Take the upload interface cancellation as an example
2final PutObjectRequest req = new PutObjectRequest(<BucketName>, <ObjectName>,
3         new FileInputStream(<FilePath>));
4Runnable cancelTask = new Runnable() {
5    @Override
6    public void run() {
7        try {
8            Thread.sleep(100);
9        } catch (InterruptedException e) {
10            e.printStackTrace()
11        }
12 // Cancel the current upload request
13        req.cancel();
14    }
15};
16new Thread(cancelTask).start();
17client.putObject(req);

Synchronous callback

The Android SDK supports the BOS server-side synchronous callback API. By setting the process parameter in the PutObjectRequest, the BOS server can actively trigger the callback API after upload completion to notify the client.

Java
1PutObjectRequest request = new PutObjectRequest({bucket}, {object}, {inputStream});
2 // Set the x-bce-process parameter
3request.setProcess({x-bce-process});
4PutObjectResponse response = client.putObject(request);
5 // Obtain the returned http status code
6int statusCode = response.getHttpResponse().getStatusCode();
7 // Obtain the data returned by the callback API
8string callbackString = response.getServerCallbackReturnBody();

View the object in the bucket.

Simple query

View the list of objects in a bucket.

  • Basic workflow

    1. Instantiate the BOSClient class.
    2. Calling the BOSClient.listObjects(bucketName) method returns an instance of the ListObjectsResponse class.
    3. For the ListObjectsResponse class, methods like getBuckets(), getOwner(), and getMetadata() can be executed.
  • Example code

    Java
    1// Obtain all object information under the specified bucket
    2ListObjectsResponse listing = client.listObjects(<BucketName>);
    3 // Traverse all objects
    4for (BosObjectSummary objectSummary : listing.getContents()) {
    5    System.out.println("ObjectKey: " + objectSummary.getKey());
    6}
    Plain Text
    1> **Note:** The listObjects() method returns a ListObjectsResponse object, which contains the results of this listObject request. Users can obtain the description information of all objects through the getContents method in ListObjectsResponse.
    2>
    3> -   By default, if the number of objects in the bucket exceeds 1,000, only 1,000 objects will be returned. In this case, the IsTruncated value in the returned result will be set to True, and NextMarker will be provided as the starting point for the next retrieval.
    4>
    5>
    6> -   To retrieve more objects, use the Marker parameter for reading in batches. Refer to [Extended Query](#Extended query).
  • Complete example

    Java
    1import android.app.Activity;
    2import android.os.Bundle;
    3import com.baidubce.BceClientException;
    4import com.baidubce.BceServiceException;
    5import com.baidubce.auth.DefaultBceCredentials;
    6import com.baidubce.demo.R;
    7import com.baidubce.services.bos.BosClient;
    8import com.baidubce.services.bos.BosClientConfiguration;
    9import com.baidubce.services.bos.model.BosObjectSummary;
    10import com.baidubce.services.bos.model.ListObjectsResponse;
    11public class ExampleActivity extends Activity {
    12private String bucketName = <BucketName>;
    13@Override
    14protected void onCreate(Bundle savedInstanceState) {
    15    super.onCreate(savedInstanceState);
    16    setContentView(R.layout.activity_main);
    17    new Thread(new Runnable() {
    18        @Override
    19        public void run() {
    20            try {
    21                BosClientConfiguration config = new BosClientConfiguration();
    22                config.setCredentials(new DefaultBceCredentials(<AccessKeyId>, <SecretAccessKey>));
    23                config.setEndpoint(<EndPoint>);
    24                BosClient client = new BosClient(config);
    25 // Obtain all object information under the specified bucket
    26                ListObjectsResponse listing = client.listObjects(<BucketName>);
    27 // Traverse all objects
    28                for (BosObjectSummary objectSummary : listing.getContents()) {
    29                    System.out.println("ObjectKey: " + objectSummary.getKey());
    30                }               	                    
    31            } catch (BceServiceException e) {
    32                System.out.println("Error ErrorCode: " + e.getErrorCode());
    33                System.out.println("Error RequestId: " + e.getRequestId());
    34                System.out.println("Error StatusCode: " + e.getStatusCode());
    35                System.out.println("Error Message: " + e.getMessage());
    36                System.out.println("Error ErrorType: " + e.getErrorType());
    37            } catch (BceClientException e) {
    38                System.out.println("Error Message: " + e.getMessage());
    39            }
    40        }
    41    }).start();
    42}}

Extended query

Users can configure the ListObjectsRequest parameters to perform advanced query operations. The extended parameters available for configuration in ListObjectsRequest include the following:

Parameter name Description Default value
MaxKeys Specify the maximum number of objects to return, which must not exceed 1,000. 1000
Prefix Set the prefix of the objectKey. The prefix means that the objectKey contains and starts with the value of Prefix.
It is usually used in conjunction with Delimiter when [querying simulated folders](#Query simulated folders).
-
Delimiter It is a delimiter used to hierarchize objectKey.
It is usually used in conjunction with Prefix when [querying simulated folders](#Query simulated folders).
The objectKey from the Prefix to the first occurrence of the Delimiter character is called: CommonPrefixes.
-
Marker It is a string used to set the starting position of the returned results.
After setting the Marker value, the returned objects will be returned starting from the Marker value in alphabetical order.
-
  • Basic workflow

    1. Create an instance of the ListObjectsRequest class.
    2. Use methods like setDelimiter(), setMarker(), or setPrefix() in ListObjectsRequest to enable more advanced query functionalities.
    3. Create an instance of the BOSClient class and invoke the listObjects(listObjectsRequest) method.
  • Example code

    Java
    1// Construct a ListObjectsRequest request
    2ListObjectsRequest listObjectsRequest = new ListObjectsRequest(<BucketName>);  
    3 // Set extended query parameters
    4listObjectsRequest.setDelimiter(<Delimiter>);
    5listObjectsRequest.setMarker(<Marker>);
    6...   
    7ListObjectsResponse listing = client.listObjects(listObjectsRequest);
    Plain Text
    1> **Note:** The above code calls an overloaded method from `listObjects` by passing a `ListObjectsRequest` to complete the request.
  • Complete example

    Example 1:

    Java
    1import android.app.Activity;
    2import android.os.Bundle;
    3import com.baidubce.BceClientException;
    4import com.baidubce.BceServiceException;
    5import com.baidubce.auth.DefaultBceCredentials;
    6import com.baidubce.demo.R;
    7import com.baidubce.services.bos.BosClient;
    8import com.baidubce.services.bos.BosClientConfiguration;
    9import com.baidubce.services.bos.model.BosObjectSummary;
    10import com.baidubce.services.bos.model.ListObjectsRequest;
    11import com.baidubce.services.bos.model.ListObjectsResponse;
    12public class ExampleActivity extends Activity {
    13private String bucketName = <BucketName>;
    14@Override
    15protected void onCreate(Bundle savedInstanceState) {
    16    super.onCreate(savedInstanceState);
    17    setContentView(R.layout.activity_main);
    18    new Thread(new Runnable() {
    19        @Override
    20        public void run() {
    21            try {
    22                BosClientConfiguration config = new BosClientConfiguration();
    23                config.setCredentials(new DefaultBceCredentials(<AccessKeyID>, <SecretAccessKey>));
    24                config.setEndpoint(<EndPoint>);
    25                BosClient client = new BosClient(config);
    26 // Construct a ListObjectsRequest request
    27                ListObjectsRequest listObjectsRequest = new ListObjectsRequest(<BucketName>);
    28 // Set parameters
    29                listObjectsRequest.setDelimiter("/");
    30                listObjectsRequest.setMarker("123");
    31                listObjectsRequest.setMaxKeys(100);
    32                listObjectsRequest.setPrefix("fun");
    33 // Obtain all eligible object information under the specified bucket
    34                ListObjectsResponse listing = client.listObjects(listObjectsRequest);
    35 // Traverse all objects
    36                for (BosObjectSummary objectSummary : listing.getContents()) {
    37                    System.out.println("ObjectKey: " + objectSummary.getKey());
    38                }                	
    39            } catch (BceServiceException e) {
    40                System.out.println("Error ErrorCode: " + e.getErrorCode());
    41                System.out.println("Error RequestId: " + e.getRequestId());
    42                System.out.println("Error StatusCode: " + e.getStatusCode());
    43                System.out.println("Error Message: " + e.getMessage());
    44                System.out.println("Error ErrorType: " + e.getErrorType());
    45            } catch (BceClientException e) {
    46                System.out.println("Error Message: " + e.getMessage());
    47            }
    48        }
    49    }).start();
    50}}

    Example II: A complete example using the NextMarker.

    Java
    1import android.app.Activity;
    2import android.os.Bundle;
    3import com.baidubce.BceClientException;
    4import com.baidubce.BceServiceException;
    5import com.baidubce.auth.DefaultBceCredentials;
    6import com.baidubce.demo.R;
    7import com.baidubce.services.bos.BosClient;
    8import com.baidubce.services.bos.BosClientConfiguration;
    9import com.baidubce.services.bos.model.BosObjectSummary;
    10import com.baidubce.services.bos.model.ListObjectsRequest;
    11import com.baidubce.services.bos.model.ListObjectsResponse;
    12public class ExampleActivity extends Activity {
    13private String bucketName = <BucketName>;
    14@Override
    15protected void onCreate(Bundle savedInstanceState) {
    16  super.onCreate(savedInstanceState);
    17  setContentView(R.layout.activity_main);
    18  new Thread(new Runnable() {
    19      @Override
    20      public void run() {
    21         try {
    22            BosClientConfiguration config = new BosClientConfiguration();
    23            config.setCredentials(new DefaultBceCredentials(<AccessKeyId>, <SecretAccessKey>);
    24            config.setEndpoint(<EndPoint>);
    25            BosClient client = new BosClient(config);
    26            ListObjectsRequest listObjectsRequest = new ListObjectsRequest(<BucketName>);
    27            listObjectsRequest.setMarker("");
    28            listObjectsRequest.setMaxKeys(20);
    29            listObjectsRequest.setDelimiter(BceConfig.BOS_DELIMITER);
    30            ListObjectsResponse listObjectsResponse = client.listObjects(listObjectsRequest);
    31            String nextMark = "";
    32            if(listObjectsResponse.isTruncated()){
    33               nextMark = listObjectsResponse.getNextMarker();
    34            }
    35           ListObjectsRequest listObjectsRequest2 = new ListObjectsRequest(<BucketName>);
    36           listObjectsRequest2.setMarker(nextMark);
    37           listObjectsRequest2.setMaxKeys(20);
    38           listObjectsRequest2.setDelimiter(BceConfig.BOS_DELIMITER);
    39           ListObjectsResponse listing = client.listObjects(listObjectsRequest2);
    40           for (BosObjectSummary objectSummary : listing.getContents()) {
    41               System.out.println("ObjectKey: " + objectSummary.getKey());
    42            }                
    43          } catch (BceServiceException e) {
    44            System.out.println("Error ErrorCode: " + e.getErrorCode());
    45            System.out.println("Error RequestId: " + e.getRequestId());
    46            System.out.println("Error StatusCode: " + e.getStatusCode());
    47            System.out.println("Error Message: " + e.getMessage());
    48            System.out.println("Error ErrorType: " + e.getErrorType());
    49         } catch (BceClientException e) {
    50            System.out.println("Error Message: " + e.getMessage());
    51         }
    52      }
    53    }).start();
    54}}

Query simulated folders

Since BOS is inherently a (<Key>,<Value>) storage system, the concept of "folder" does not exist in principle. However, you can simulate the folder function by combining the Delimiter and Prefix} parameters.

Suppose the bucket contains five files: bos.jpg, fun/, fun/test.jpg, fun/movie/001.avi, and fun/movie/007.avi. The "/" symbol can be used as a delimiter to mimic folder structures.

Recursively list all files under the simulated folder

You can obtain all files under a simulated folder by setting the Prefix parameter:

Java
1// Construct a ListObjectsRequest request
2ListObjectsRequest listObjectsRequest = new ListObjectsRequest(<BucketName>);
3 // Recursively list all files under the fun directory
4listObjectsRequest.setPrefix("fun/");
5ListObjectsResponse listing = client.listObjects(listObjectsRequest);
6 // Traverse all objects
7System.out.println("Objects:");
8for (BosObjectSummary objectSummary : listing.getContents()) {
9   System.out.println(objectSummary.getKey());
10}

Output:

Java
1Objects:
2fun/
3fun/movie/001.avi
4fun/movie/007.avi
5fun/test.jpg

View files and subfolders under the simulated folder

With the combination of Prefix and Delimiter, it can list files and subfolders under the simulated folder:

Java
1// Construct a ListObjectsRequest request
2ListObjectsRequest listObjectsRequest = new ListObjectsRequest(<BucketName>);
3 // Specify "/" as the delimiter for simulated folder
4listObjectsRequest.setDelimiter("/");
5 // List all files and subfolders under the “fun” folder
6listObjectsRequest.setPrefix("fun/");
7ListObjectsResponse listing = client.listObjects(listObjectsRequest);
8 // Traverse all objects
9System.out.println("Objects:");
10for (BosObjectSummary objectSummary : listing.getContents()) {
11   System.out.println(objectSummary.getKey());
12}
13 // Traverse all CommonPrefix
14System.out.println("\nCommonPrefixs:");
15for (String commonPrefix : listing.getCommonPrefixes()) {
16   System.out.println(commonPrefix);
17}

Output:

Java
1Objects:
2fun/
3fun/test.jpg
4CommonPrefixs:
5fun/movie/

Description:

In the returned results, the list under Objects shows the files under the fun folder. The list in CommonPrefixs shows all subfolders under the fun folder. It can be seen that the two files fun/movie/001.avi and fun/movie/007.avi are not listed because they belong to the movie subfolder under the fun folder.

Get Object

Simple object get

Users can load the object into a stream by using the following code.

  • Basic workflow

    1. Instantiate the BOSClient class.
    2. By calling the BOSClient.getObject() method, the specified BosObject will be returned.
    3. Load the BosObject into a stream for further processing.
  • Example code

    Java
    1//Obtain the object, with returned result BosObject object
    2BosObject object = client.getObject(<BucketName>, <ObjectKey>);
    3 // Retrieve ObjectMeta
    4ObjectMetadata meta = object.getObjectMetadata();
    5 //Obtain the object's input stream
    6InputStream objectContent = object.getObjectContent();
    7 // Process object
    8...
    9 // Close stream
    10objectContent.close();
    Plain Text
    1> **Note:**
    2>
    3> -   The BosObject includes various details about the object, such as the bucket it belongs to, the object’s name, metadata, and an input stream. Users can read the object's content into a file or memory by interacting with the input stream.
    4> -   ObjectMetadata contains information such as the ETag defined during object upload, HTTP headers, and custom metadata.
    5> -   Using the getObjectContent() method of BosObject, users can access the input stream of the returned object, enabling them to read and process the object's content.
  • Complete example

    Java
    1import java.io.BufferedReader;
    2import java.io.IOException;
    3import java.io.InputStream;
    4import java.io.InputStreamReader;
    5import android.app.Activity;
    6import android.os.Bundle;
    7import com.baidubce.BceClientException;
    8import com.baidubce.BceServiceException;
    9import com.baidubce.auth.DefaultBceCredentials;
    10import com.baidubce.demo.R;
    11import com.baidubce.services.bos.BosClient;
    12import com.baidubce.services.bos.BosClientConfiguration;
    13import com.baidubce.services.bos.model.BosObject;
    14import com.baidubce.services.bos.model.ObjectMetadata;
    15public class ExampleActivity extends Activity {
    16private String bucketName = <BucketName>;
    17private String objectKey = <ObjectKey>;
    18@Override
    19protected void onCreate(Bundle savedInstanceState) {
    20    super.onCreate(savedInstanceState);
    21    setContentView(R.layout.activity_main);
    22    new Thread(new Runnable() {
    23        @Override
    24        public void run() {
    25            try {
    26                BosClientConfiguration config = new BosClientConfiguration();
    27                config.setCredentials(new DefaultBceCredentials(<AccessKeyID>, <SecretAccessKey>));
    28                config.setEndpoint(<EndPoint>);
    29                BosClient client = new BosClient(config);
    30 //Obtain the object, with returned result BosObject object
    31                BosObject object = client.getObject(<BucketName>, <ObjectKey>);
    32 // Retrieve ObjectMeta
    33                ObjectMetadata meta = object.getObjectMetadata();
    34 //Obtain the object's input stream
    35                InputStream objectContent = object.getObjectContent();
    36 // Process object
    37                FileOutputStream fos=new FileOutputStream(android.os.Environment.getExternalStorageDirectory()+"/1/file");  
    38                byte[] buffer=new byte[<bufferSize>];  
    39                int count=0;  
    40                while ((count=objectContent.read(buffer))>=0) {  
    41                    fos.write(buffer,0,count);  
    42                }  
    43                System.out.println(meta.getETag());
    44                System.out.println(meta.getContentLength());
    45 // Close stream
    46                objectContent.close();
    47                fos.close();
    48            } catch (BceServiceException e) {
    49                System.out.println("Error ErrorCode: " + e.getErrorCode());
    50                System.out.println("Error RequestId: " + e.getRequestId());
    51                System.out.println("Error StatusCode: " + e.getStatusCode());
    52                System.out.println("Error Message: " + e.getMessage());
    53                System.out.println("Error ErrorType: " + e.getErrorType());
    54            } catch (BceClientException e) {
    55                System.out.println("Error Message: " + e.getMessage());
    56            } catch (IOException e) {
    57                // TODO Auto-generated catch block
    58                e.printStackTrace();
    59            }
    60        }
    61    }).start();
    62}}

Obtain object via GetObjectRequest

To unlock more capabilities, GetObjectRequest can be used to retrieve objects.

  • Basic workflow

    1. Create an instance of the GetObjectRequest class.
    2. Invoke the setRange() method on GetObjectRequest to retrieve specific byte ranges from the object.
    3. Execute the client.getObject() operation.
  • Example code

    Java
    1// Create GetObjectRequest
    2GetObjectRequest getObjectRequest = new GetObjectRequest(<BucketName>, <ObjectKey>);
    3 // Obtain data within the 0~100 byte range
    4getObjectRequest.setRange(0, 100);
    5 //Obtain the object, with returned result BosObject object
    6BosObject object = client.getObject(getObjectRequest);
    Plain Text
    1> **Note:** The setRange() method in GetObjectRequest allows users to specify a range for the returned object. This feature can be used to implement segmented downloads and resumable uploads.

Obtain download progress

Users can track download progress via a callback function.

The SDK offers a download progress callback API, which allows you to define necessary operations during the upload process, such as updating the API.

Java
1public interface BceProgressCallback<T extends AbstractBceRequest> {
2 // request is the download request
3 // currentSize is the current download size (unit: byte)
4 // totalSize is the total size to be downloaded in this request (unit: byte)
5          void onProgress(T request, long currentSize, long totalSize);
6    }
  • Example code

    Java
    1GetObjectRequest request = new GetObjectRequest()
    2        .withBucketName(this.bucketName)
    3        .withKey(objectKey)
    4        .withRange(0, 5);
    5request.setProgressCallback(new BosProgressCallback<GetObjectRequest>() {
    6    @Override
    7    public void onProgress(GetObjectRequest request, long currentSize, long totalSize) {
    8        Log.e(currentSize + "", totalSize + "");
    9    }
    10});
    11InputStream input = this.client.getObject(request).getObjectContent();
    Plain Text
    1> **Note:** The download progress interface differs from the upload progress interface. It is not possible to specify the fragment size of the increase in the download volume during each callback.

Download object to a specified path

Users can use the following code to directly download an object to a specified path.

  • Basic workflow

    1. Create an instance of the GetObjectRequest class.
    2. Execute the client.getObject() operation.
    3. Download an object directly to a specified path.
  • Example code

    Java
    1// Create GetObjectRequest
    2GetObjectRequest getObjectRequest = new GetObjectRequest(<BucketName>, <ObjectKey>);
    3 // Download object to file
    4ObjectMetadata objectMetadata = client.getObject(getObjectRequest, new File("/path/to/file","w+"));
    Plain Text
    1> **Note:** When using the above method to directly download an object to a specified path, the method returns an ObjectMetadata object.

Obtain the storageClass of an object

The storage classes of an object are categorized as STANDARD (standard storage), STANDARD_IA (infrequent access storage), COLD (cold storage), and ARCHIVE (archive storage).

Example code

Java
1public void getObjectStorageClass(){
2  //...
3ObjectMetadata meta = client.getObjectMetadata(bucketName, key);
4String storageClass = meta.getStorageClass();
5}

Obtain only ObjectMetadata

The getObjectMetadata() method retrieves only the ObjectMetadata, without obtaining the object itself.

Example code

Java
1ObjectMetadata objectMetadata = client.getObjectMetadata(<BucketName>, <ObjectKey>);

Get object URL

The following code allows you to get the URL of a specific object, which is commonly used for temporarily sharing the object's URL with others.

  • Basic workflow

    1. Instantiate the BOSClient class.
    2. Call the BOSClient.generatePresignedUrl() method.
    3. The method returns the URL of the object.
  • Example code

    Java
    1URL url = client.generatePresignedUrl(<BucketName>, <ObjectKey>, <ExpirationInSeconds>);
    Plain Text
    1> **Note:**` ExpirationInSeconds` is the specified URL validity period, calculated from the current time. It is an optional parameter, and the system default value is 1,800 s if not configured. To set a permanent non-expiration time, the `ExpirationInSeconds` parameter can be set to -1. You cannot set it to any other negative value.
  • Complete example

    Java
    1import java.net.URL;
    2import android.app.Activity;
    3import android.content.Intent;
    4import android.net.Uri;
    5import android.os.Bundle;
    6import com.baidubce.BceClientException;
    7import com.baidubce.BceServiceException;
    8import com.baidubce.auth.DefaultBceCredentials;
    9import com.baidubce.demo.R;
    10import com.baidubce.services.bos.BosClient;
    11import com.baidubce.services.bos.BosClientConfiguration;
    12public class ExampleActivity extends Activity {
    13private String bucketName = <BucketName>;
    14private String objectKey = <ObjectKey>;
    15@Override
    16protected void onCreate(Bundle savedInstanceState) {
    17    super.onCreate(savedInstanceState);
    18    setContentView(R.layout.activity_main);
    19    new Thread(new Runnable() {
    20        @Override
    21        public void run() {
    22            try {
    23                BosClientConfiguration config = new BosClientConfiguration();
    24                config.setCredentials(new DefaultBceCredentials(<AccessKeyID>, <SecretAccessKey>));
    25                config.setEndpoint(<EndPoint>);
    26                BosClient client = new BosClient(config);
    27 //Obtain the object URL
    28                URL url = client.generatePresignedUrl(<BucketName>, <ObjectKey>, 2000);  
    29                Uri uri = Uri.parse(url.toString());
    30                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    31 // Execute URL
    32                startActivity(intent);
    33            } catch (BceServiceException e) {
    34                System.out.println("Error ErrorCode: " + e.getErrorCode());
    35                System.out.println("Error RequestId: " + e.getRequestId());
    36                System.out.println("Error StatusCode: " + e.getStatusCode());
    37                System.out.println("Error Message: " + e.getMessage());
    38                System.out.println("Error ErrorType: " + e.getErrorType());
    39            } catch (BceClientException e) {
    40                System.out.println("Error Message: " + e.getMessage());
    41            }
    42        }
    43    }).start();
    44}}

Object permission control

Set access permission for an object.

Currently, BOS provides two ways to configure ACLs. The first is to use Canned ACL. During PutObjectAcl, object permissions are set through the headers "x-bce-acl" or "x-bce-grant-permission". Available permission options include private and public-read. Note that these two headers cannot be included in the same request. The second method involves uploading an ACL file.

For details, refer to Setting Object Permission Control..

  1. Set object access permission using the headers "x-bce-acl" or "x-bce-grant-permission"
  • set object acl First method (Set via request headers)
Java
1SetObjectAclRequest setObjectAclRequest = new SetObjectAclRequest("yourBucketName","objectKey",CannedAccessControlList.PublicRead);
2client.setObjectAcl(setObjectAclRequest);
  • set object acl First method (Set xBceGrantRead via request headers)
Java
1String xBceGrantRead = "id=\"user_id1\""+",id=\"user_id2\"";
2SetObjectAclRequest setObjectAclRequest = new SetObjectAclRequest();
3setObjectAclRequest.withBucketName("yourBucketName");
4setObjectAclRequest.withKey("objectKey");
5setObjectAclRequest.setxBceGrantRead(xBceGrantRead);
6client.setObjectAcl(setObjectAclRequest);
  • set object acl First method (Set xBceGrantFullControl via request headers)
Java
1String xBceGrantFullControl = "id=\"user_id1\""+",id=\"user_id2\"";
2SetObjectAclRequest setObjectAclRequest = new SetObjectAclRequest();
3setObjectAclRequest.withBucketName("yourBucketName");
4setObjectAclRequest.withKey("objectKey");
5setObjectAclRequest.setxBceGrantFullControl(xBceGrantFullControl);
6client.setObjectAcl(setObjectAclRequest);
  1. Set object access permission via setObjectAcl
  • set object acl Second Method (JSON string)
Java
1String jsonObjectAcl = "{\"accessControlList\":["+ "{\"grantee\":[{\"id\":\"*\"}], "+ "\"permission\":[\"FULL_CONTROL\"]"+"}]}";
2SetObjectAclRequest setObjectAclRequest = new SetObjectAclRequest("yourBucketName","objectKey",jsonObjectAcl);
3client.setObjectAcl(setObjectAclRequest);
  • set object acl Second Method, by which users only need to specify the specified parameters
Java
1List<Grant> grants = new ArrayList<Grant>();
2List<Grantee> grantees = new ArrayList<Grantee>();
3List<Permission> permissions = new ArrayList<Permission>();
4 // Grant permission to specific user
5grantees.add(new Grantee("user_id1"));
6grantees.add(new Grantee("user_id2"));
7grantees.add(new Grantee("user_id3"));
8 // Set permissions
9permissions.add(Permission.READ);
10grants.add(new Grant().withGrantee(grantees).withPermission(permissions));
11SetObjectAclRequest setObjectAclRequest = new SetObjectAclRequest("yourBucketName","objectKey", grants);
12client.setObjectAcl(setObjectAclRequest);

View object permissions

The following code can be used to check the object permissions:

Java
1GetObjectAclRequest getObjectRequest = new GetObjectAclRequest();
2getObjectRequest.withBucketName("yourBucketName");
3getObjectRequest.withKey("objectKey");
4GetObjectAclResponse response = client.getObjectAcl(getObjectRequest);

The parameters available for calling in the resolution class returned by the getObjectAcl method are as follows:

Parameters Description
accessControlList Identify the permission list of the object
grantee Identify the grantee
-id Authorized person ID
permission Identify the grantee permissions

Delete object permissions

The following code can be used to delete the object permissions:

Java
1DeleteObjectAclRequest deleteObjectAclRequest = new DeleteObjectAclRequest("yourBucketName","objectKey");
2client.deleteObjectAcl(deleteObjectAclRequest);

Delete Object

  • Basic workflow

    1. Instantiate the BOSClient class.
    2. Invoke the BOSClient.deleteObject() method.
    3. If the operation fails, an exception is thrown; if successful, no return value is provided.
  • Example code

    Java
    1// Delete Object
    2 client.deleteObject(<BucketName>, <ObjectKey>);   //Specify the name of the bucket where the object to be deleted is located and the name of the object
  • Complete example

    Java
    1import android.app.Activity;
    2import android.os.Bundle;
    3import com.baidubce.BceClientException;
    4import com.baidubce.BceServiceException;
    5import com.baidubce.auth.DefaultBceCredentials;
    6import com.baidubce.demo.R;
    7import com.baidubce.services.bos.BosClient;
    8import com.baidubce.services.bos.BosClientConfiguration;
    9public class ExampleActivity extends Activity {
    10private String bucketName = <BucketName>;
    11private String objectKey = <ObjectKey>;
    12@Override
    13protected void onCreate(Bundle savedInstanceState) {
    14    super.onCreate(savedInstanceState);
    15    setContentView(R.layout.activity_main);
    16    new Thread(new Runnable() {
    17        @Override
    18        public void run() {
    19            try {
    20                BosClientConfiguration config = new BosClientConfiguration();
    21                config.setCredentials(new DefaultBceCredentials(<AccessKeyID>, <SecretAccessKey>));
    22                config.setEndpoint(<EndPoint>);
    23                BosClient client = new BosClient(config);
    24 // Delete Object
    25 client.deleteObject(<BucketName>, <ObjectKey>);   //Specify the name of the bucket where the object to be deleted is located and the name of the object
    26            } catch (BceServiceException e) {
    27                System.out.println("Error ErrorCode: " + e.getErrorCode());
    28                System.out.println("Error RequestId: " + e.getRequestId());
    29                System.out.println("Error StatusCode: " + e.getStatusCode());
    30                System.out.println("Error Message: " + e.getMessage());
    31                System.out.println("Error ErrorType: " + e.getErrorType());
    32            } catch (BceClientException e) {
    33                System.out.println("Error Message: " + e.getMessage());
    34            }
    35        }
    36    }).start();
    37}}

Copy Object

Simply Copy Object

  • Basic workflow

    1. Instantiate the BOSClient class.
    2. Call the BOSClient.copyObject() method.
    3. The method returns a CopyObjectResponse instance. The eTag and last modification time can be obtained through getETag() and getLastModified().
  • Example code

    Java
    1// Copy Object
    2 CopyObjectResponse copyObjectResponse = client.copyObject(<SrcBucketName>, <SrcKey>, <DestBucketName>, <DestKey>);  //SrcBucketName, SrcKey are the source addresses,DestBucketName, DestKey are the destination addresses to which the copy is made
    3 // Print results
    4System.out.println("ETag: " + copyObjectResponse.getETag() + " LastModified: " + copyObjectResponse.getLastModified());
  • Complete example

    Java
    1import android.app.Activity;
    2import android.os.Bundle;
    3import com.baidubce.BceClientException;
    4import com.baidubce.BceServiceException;
    5import com.baidubce.auth.DefaultBceCredentials;
    6import com.baidubce.demo.R;
    7import com.baidubce.services.bos.BosClient;
    8import com.baidubce.services.bos.BosClientConfiguration;
    9import com.baidubce.services.bos.model.CopyObjectResponse;
    10public class ExampleActivity extends Activity {
    11private String srcBucketName = <SrcBucketName>;
    12private String srcKey = <SrcKey>;
    13private String destBucketName = <DestBucketName>;
    14private String destKey = <DestKey>;
    15@Override
    16protected void onCreate(Bundle savedInstanceState) {
    17    super.onCreate(savedInstanceState);
    18    setContentView(R.layout.activity_main);
    19    new Thread(new Runnable() {
    20        @Override
    21        public void run() {
    22            try {
    23                BosClientConfiguration config = new BosClientConfiguration();
    24                config.setCredentials(new DefaultBceCredentials(<AccessKeyID>, <SecretAccessKey>));
    25                config.setEndpoint(<EndPoint>);
    26                BosClient client = new BosClient(config);
    27 // Copy Object
    28                CopyObjectResponse copyObjectResponse = client.copyObject(<SrcBucketName>, <SrcKey>, <DestBucketName>, <DestKey>);
    29 // Print results
    30                System.out.println("ETag: " + copyObjectResponse.getETag() + " LastModified: " + copyObjectResponse.getLastModified());
    31            } catch (BceServiceException e) {
    32                System.out.println("Error ErrorCode: " + e.getErrorCode());
    33                System.out.println("Error RequestId: " + e.getRequestId());
    34                System.out.println("Error StatusCode: " + e.getStatusCode());
    35                System.out.println("Error Message: " + e.getMessage());
    36                System.out.println("Error ErrorType: " + e.getErrorType());
    37            } catch (BceClientException e) {
    38                System.out.println("Error Message: " + e.getMessage());
    39            }
    40        }
    41    }).start();
    42}}
    Plain Text
    1> **Note:** The copyObject method returns a `CopyObjectResponse` object containing the new object's ETag and modification time.

Copy Object via CopyObjectRequest

You can also copy object via CopyObjectRequest This function is typically used in the following scenarios:

  • Copy an object while resetting its metadata.
  • Reset the metadata of an existing object (set the source and destination to the same object).
  • Basic workflow

    1. Create an instance of the CopyObjectRequest class, and pass in the parameters <SrcBucketName>, <SrcKey>, <DestBucketName>, <DestKey>.
    2. Create an ObjectMetadata instance.
    3. The method returns a CopyObjectResponse instance. The eTag and last modification time can be obtained through getETag() and getLastModified().
  • Example code

    Java
    1// Create CopyObjectRequest object
    2CopyObjectRequest copyObjectRequest = new CopyObjectRequest(<SrcBucketName>, <SrcKey>, <DestBucketName>, <DestKey>);
    3 // Set new Metadata
    4Map<String, String> userMetadata = new HashMap<String, String>();
    5userMetadata.put(<UserMetaKey>,<UserMetaValue>);
    6meta.setUserMetadata(userMetadata);
    7copyObjectRequest.setNewObjectMetadata(meta);
    8 // Copy Object
    9CopyObjectResponse copyObjectResponse = client.copyObject(copyObjectRequest);
    10System.out.println("ETag: " + copyObjectResponse.getETag() + " LastModified: " + copyObjectResponse.getLastModified());
    Plain Text
    1> **Note:**` CopyObjectRequest` allows users to modify the ObjectMeta of the target object and also provides the setting of the `MatchingETagConstraints` parameter.

Multipart upload of objects

Multipart Upload Scenarios

In addition to using the putObject() method for file uploads to BOS, BOS also supports another upload mode called Multipart Upload. This mode can be used in scenarios such as:

  • When resumable uploads are required.
  • When uploading files larger than 5GB.
  • When the connection to the BOS server is frequently interrupted due to unstable network conditions.
  • Enable streaming file uploads.
  • The file size cannot be determined before uploading.

Multipart Upload Process

Suppose there is a file with the local path /path/to/file.zip. Since the file is large, multipart upload is used to transmit it to BOS.

  • Basic workflow

    1. Start a multipart upload.
    2. Upload individual parts.
    3. Finalize the multipart upload.

Initialize Multipart Upload

Use initiateMultipartUpload method to initialize a multipart upload event:

  • Example code

    Java
    1// Initiate Multipart Upload
    2InitiateMultipartUploadRequest initiateMultipartUploadRequest =
    3      new InitiateMultipartUploadRequest(<BucketName>, <ObjectKey>);
    4InitiateMultipartUploadResponse initiateMultipartUploadResponse =
    5      client.initiateMultipartUpload(initiateMultipartUploadRequest);
    6 // Print UploadId
    7System.out.println("UploadId: " + initiateMultipartUploadResponse.getUploadId());
    Plain Text
    1> **Note:** The return result of `initiateMultipartUpload` contains `UploadId`, which is the unique identifier for distinguishing multipart upload events, and we will use it in subsequent operations.

Upload parts

Upload the file in segments.

  • Example code

    Java
    1// Set each part to 5MB
    2final long partSize = 1024 * 1024 * 5L;
    3File partFile = new File("/path/to/file.zip");
    4 // Calculate the count of parts
    5int partCount = (int) (partFile.length() / partSize);
    6if (partFile.length() % partSize != 0) {
    7    partCount++;
    8}
    9 // Create a list to save the ETag and PartNumber of each uploaded part
    10List<PartETag> partETags = new ArrayList<PartETag>();
    11 // Get file stream
    12FileInputStream fis = new FileInputStream(partFile);
    13for (int i = 0; i < partCount; i++) {
    14 // Calculate the size of each part
    15    long skipBytes = partSize * i;
    16    long size = partSize < partFile.length() - skipBytes ?
    17              partSize : partFile.length() - skipBytes;
    18    byte[] buf = new byte[(int)size];
    19    int offset = 0;
    20    while (true) {
    21        int byteRead = fis.read(buf, offset, (int)size);
    22        offset += byteRead;
    23        if (byteRead < 0 || offset >= size) {
    24           break;
    25        }
    26    }
    27    ByteArrayInputStream bufStream = new ByteArrayInputStream(buf);
    28 // Create UploadPartRequest to upload parts
    29    UploadPartRequest uploadPartRequest = new UploadPartRequest();
    30    uploadPartRequest.setBucketName(bucketName);
    31    uploadPartRequest.setKey(objectkey);
    32    uploadPartRequest.setUploadId(initiateMultipartUploadResponse.getUploadId());
    33    uploadPartRequest.setInputStream(bufStream);
    34    uploadPartRequest.setPartSize(size);
    35    uploadPartRequest.setPartNumber(i + 1);
    36 // Upload progress callback
    37    uploadPartRequest.setProgressCallback(new BosProgressCallback<UploadPartRequest>() {
    38        @Override
    39        public void onProgress(UploadPartRequest request, long currentSize, long totalSize) {
    40            Log.e(currentSize + "", totalSize + "");
    41        }
    42    });
    43    UploadPartResponse uploadPartResponse = client.uploadPart(uploadPartRequest);
    44 // Save the returned PartETag to the List.
    45    partETags.add(uploadPartResponse.getPartETag());
    46    System.out.println(uploadPartResponse.getPartETag());
    47  }
    48 // Close the file
    49  fis.close();
    Plain Text
    1> **Note:** The core of the above code is to call the `UploadPart` method to upload each part concurrently, but the following points should be noted:
    2>
    3> -   The UploadPart method requires the size of each part to either be an integer multiple of 1MB or greater than 5MB. However, the Upload Part interface does not validate the part size immediately; this check happens only during the finalization of the multipart upload.  
    4> -   To ensure no errors during network transmission, it is recommended to use the Content-MD5 value returned by BOS for each part after `UploadPart` to verify the correctness of the uploaded part data. When all part data is combined into one Object, it no longer contains the MD5 value.
    5> -   The part number must be within the range of 1 to 10,000. If this limit is exceeded, BOS will return an InvalidArgument error code.  
    6> -   For each uploaded part, the stream must be positioned at the beginning of the respective part.  
    7> -   After each Part upload, the return result of BOS will include a `PartETag` object, which is a combination of the uploaded block's ETag and block number (PartNumber). It will be used in subsequent steps to complete the multipart upload, so it must be saved. Generally speaking, these `PartETag` objects will be saved in a List.
    8> -   For details on using the progress callback API, refer to the chapter titled "Obtain Upload Progress."  

Complete multipart upload

  • Example code

    Java
    1CompleteMultipartUploadRequest completeMultipartUploadRequest =
    2      new CompleteMultipartUploadRequest(<BucketName>, <ObjectKey>,
    3            initiateMultipartUploadResponse.getUploadId(), partETags);
    4 // Complete multipart upload
    5CompleteMultipartUploadResponse completeMultipartUploadResponse =
    6      client.completeMultipartUpload(completeMultipartUploadRequest);
    7 // Print Object's ETag
    8System.out.println(completeMultipartUploadResponse.getETag());
    Plain Text
    1> **Note:** The `partETags` in the above code is the list of partETag saved in the second step. After BOS receives the Part list submitted by the user, it will verify the validity of each data Part one by one. Once all data parts are validated, BOS will assemble the data parts into a complete Object.
  • Complete example

    Java
    1import java.io.File;
    2import java.io.FileInputStream;
    3import java.io.IOException;
    4import java.util.ArrayList;
    5import java.util.List;
    6import org.json.JSONException;
    7import android.app.Activity;
    8import android.os.Bundle;
    9import com.baidubce.BceClientException;
    10import com.baidubce.BceServiceException;
    11import com.baidubce.auth.DefaultBceCredentials;
    12import com.baidubce.demo.R;
    13import com.baidubce.services.bos.BosClient;
    14import com.baidubce.services.bos.BosClientConfiguration;
    15import com.baidubce.services.bos.model.CompleteMultipartUploadRequest;
    16import com.baidubce.services.bos.model.CompleteMultipartUploadResponse;
    17import com.baidubce.services.bos.model.InitiateMultipartUploadRequest;
    18import com.baidubce.services.bos.model.InitiateMultipartUploadResponse;
    19import com.baidubce.services.bos.model.PartETag;
    20import com.baidubce.services.bos.model.UploadPartRequest;
    21import com.baidubce.services.bos.model.UploadPartResponse;
    22public class ExampleActivity extends Activity {
    23private String bucketName = <BucketName>;
    24private String objectKey = <ObjectKey>;
    25​    
    26@Override
    27protected void onCreate(Bundle savedInstanceState) {
    28    super.onCreate(savedInstanceState);
    29    setContentView(R.layout.activity_main);
    30    new Thread(new Runnable() {
    31        @Override
    32        public void run() {
    33            try {
    34              BosClientConfiguration config = new BosClientConfiguration();
    35              config.setCredentials(new DefaultBceCredentials(<AccessKeyID>, <SecretAccessKey>));
    36              config.setEndpoint(<EndPoint>);
    37              BosClient client = new BosClient(config);
    38 // Initiate Multipart Upload
    39              InitiateMultipartUploadRequest initiateMultipartUploadRequest = new InitiateMultipartUploadRequest(<BucketName>, <ObjectKey>);
    40              InitiateMultipartUploadResponse initiateMultipartUploadResponse =
    41                        client.initiateMultipartUpload(initiateMultipartUploadRequest);
    42 // Print UploadId
    43              System.out.println("UploadId: " + initiateMultipartUploadResponse.getUploadId());
    44 // Set each part to 5MB
    45              final long partSize = 1024 * 1024 * 5L;
    46              File partFile = new File("/path/to/file.zip");
    47 // Calculate the count of parts
    48              int partCount = (int) (partFile.length() / partSize);
    49              if (partFile.length() % partSize != 0) {
    50                  partCount++;
    51              }
    52 // Create a list to save the ETag and PartNumber of each uploaded part
    53              List<PartETag> partETags = new ArrayList<PartETag>();
    54 // Get file stream
    55              FileInputStream fis = new FileInputStream(partFile);
    56              for (int i = 0; i < partCount; i++) {                       
    57 // Calculate the size of each part
    58                  long skipBytes = partSize * i;
    59                  long size = partSize < partFile.length() - skipBytes ?
    60                          partSize : partFile.length() - skipBytes;
    61                  byte[] buf = new byte[(int)size];
    62                  int offset = 0;
    63                  while (true) {
    64                      int byteRead = fis.read(buf, offset, (int)size);
    65                      offset += byteRead;
    66                      if (byteRead < 0 || offset >= size) {
    67                          break;
    68                      }
    69                  }
    70                  ByteArrayInputStream bufStream = new ByteArrayInputStream(buf);
    71 // Create UploadPartRequest to upload parts
    72                  UploadPartRequest uploadPartRequest = new UploadPartRequest();
    73                  uploadPartRequest.setBucketName(<BucketName>);
    74                  uploadPartRequest.setKey(<ObjectKey>);
    75                  uploadPartRequest.setUploadId(initiateMultipartUploadResponse.getUploadId());
    76                  uploadPartRequest.setInputStream(fis);
    77                  uploadPartRequest.setPartSize(size);
    78                  uploadPartRequest.setPartNumber(i + 1);
    79                  UploadPartResponse uploadPartResponse = client.uploadPart(uploadPartRequest);
    80 // Save the returned PartETag to the List.
    81                  partETags.add(uploadPartResponse.getPartETag());
    82                  System.out.println(uploadPartResponse.getPartETag());                                         
    83              }
    84 // Close the file
    85              fis.close();
    86              CompleteMultipartUploadRequest completeMultipartUploadRequest = new CompleteMultipartUploadRequest(<BucketName>, <ObjectKey>, initiateMultipartUploadResponse.getUploadId(), partETags);
    87 // Complete multipart upload
    88              CompleteMultipartUploadResponse completeMultipartUploadResponse =
    89                      client.completeMultipartUpload(completeMultipartUploadRequest);
    90 // Print Object's ETag
    91              System.out.println(completeMultipartUploadResponse.getETag());
    92            } catch (BceServiceException e) {
    93                System.out.println("Error ErrorCode: " + e.getErrorCode());
    94                System.out.println("Error RequestId: " + e.getRequestId());
    95                System.out.println("Error StatusCode: " + e.getStatusCode());
    96                System.out.println("Error Message: " + e.getMessage());
    97                System.out.println("Error ErrorType: " + e.getErrorType());
    98            } catch (BceClientException e) {
    99                System.out.println("Error Message: " + e.getMessage());
    100            } catch (IOException e) {
    101                // TODO Auto-generated catch block
    102                e.printStackTrace();
    103            } catch (JSONException e) {
    104                // TODO Auto-generated catch block
    105                e.printStackTrace();
    106            }
    107        }
    108    }).start();
    109}}

Cancel multipart upload

Users can cancel multipart uploads by using the abortMultipartUpload method.

  • Example code

    Java
    1AbortMultipartUploadRequest abortMultipartUploadRequest =
    2    new AbortMultipartUploadRequest(<BucketName>, <ObjectKey>, <UploadId>);
    3 // Cancel multipart upload
    4client.abortMultipartUpload(abortMultipartUploadRequest);

Retrieve unfinished multipart uploads

Users can obtain the unfinished multipart upload events in the bucket by the listMultipartUploads method.

  • Basic workflow

    1. Create an instance of the listMultipartUploadsRequest class, and pass in the parameter <BucketName>.
    2. Create a BOSClient instance and invoke the BOSClient.listMultipartUploads() method.
    3. The listMultipartUploads() method provides details about all uploaded parts.
  • Example code

    Java
    1ListMultipartUploadsRequest listMultipartUploadsRequest =
    2    new ListMultipartUploadsRequest(<BucketName>);
    3 // Retrieve all upload events within the bucket
    4ListMultipartUploadsResponse list = client.listMultipartUploads(listMultipartUploadsRequest);
    5​    
    6 // Traverse all upload events
    7for (MultipartUploadSummary multipartUpload : list.getMultipartUploads()) {
    8    System.out.println("Key: " + multipartUpload.getKey() + " UploadId: " + multipartUpload.getUploadId());
    9}
    Plain Text
    1> **Note:**
    2>
    3> -   By default, if the number of multipart upload events in a bucket surpasses 1,000, only 1,000 records will be returned. In such cases, the IsTruncated value in the response will be True, and the NextKeyMarker will indicate the starting point for the next query.  
    4> -   To fetch more multipart upload events, use the KeyMarker parameter to retrieve data in batches.  
  • Complete example

    Java
    1import android.app.Activity;
    2import android.os.Bundle;
    3import com.baidubce.BceClientException;
    4import com.baidubce.BceServiceException;
    5import com.baidubce.auth.DefaultBceCredentials;
    6import com.baidubce.demo.R;
    7import com.baidubce.services.bos.BosClient;
    8import com.baidubce.services.bos.BosClientConfiguration;
    9import com.baidubce.services.bos.model.ListMultipartUploadsRequest;
    10import com.baidubce.services.bos.model.ListMultipartUploadsResponse;
    11import com.baidubce.services.bos.model.MultipartUploadSummary;
    12public class ExampleActivity extends Activity {
    13private String bucketName = <BucketName>;
    14@Override
    15protected void onCreate(Bundle savedInstanceState) {
    16    super.onCreate(savedInstanceState);
    17    setContentView(R.layout.activity_main);
    18    new Thread(new Runnable() {
    19        @Override
    20        public void run() {
    21            try {
    22                BosClientConfiguration config = new BosClientConfiguration();
    23                config.setCredentials(new DefaultBceCredentials(<AccessKeyID>, <SecretAccessKey>));
    24                config.setEndpoint(<EndPoint>);
    25                BosClient client = new BosClient(config);
    26                ListMultipartUploadsRequest listMultipartUploadsRequest =
    27                        new ListMultipartUploadsRequest(<BucketName>);
    28 // Retrieve all upload events within the bucket
    29                ListMultipartUploadsResponse listing = client.listMultipartUploads(listMultipartUploadsRequest);
    30 // Traverse all upload events
    31                 for (MultipartUploadSummary multipartUpload : listing.getMultipartUploads()) {
    32                     System.out.println("Key: " + multipartUpload.getKey() + " UploadId: " + multipartUpload.getUploadId());
    33                 }
    34            } catch (BceServiceException e) {
    35                System.out.println("Error ErrorCode: " + e.getErrorCode());
    36                System.out.println("Error RequestId: " + e.getRequestId());
    37                System.out.println("Error StatusCode: " + e.getStatusCode());
    38                System.out.println("Error ErrorType: " + e.getErrorType());
    39                System.out.println("Error Message: " + e.getMessage());
    40            } catch (BceClientException e) {
    41                System.out.println("Error Message: " + e.getMessage());
    42            }
    43        }
    44    }).start();
    45}}

Get all uploaded part information

Users can obtain all uploaded parts in an upload event by the listParts method.

  • Basic workflow

    1. Create an instance of the ListPartsRequest class, and pass in the parameters <BucketName>, <ObjectKey> and <UploadId>
    2. Create a BOSClient instance and invoke the BOSClient.listParts() method.
    3. The listParts() method provides details about all uploaded parts.
  • Example code

    Java
    1ListPartsRequest listPartsRequest = new ListPartsRequest(<BucketName>, <ObjectKey>, <UploadId>);
    2​    
    3 // Retrieve all uploaded part information
    4ListPartsResponse partListing = client.listParts(listPartsRequest);
    5​    
    6 // Traverse all parts
    7for (PartSummary part : partListing.getParts()) {
    8    System.out.println("PartNumber: " + part.getPartNumber() + " ETag: " + part.getETag());
    9}
    Plain Text
    1> **Note:**
    2>
    3> -   By default, if the number of multipart upload events in a bucket surpasses 1,000, only 1,000 records will be returned. In such cases, the IsTruncated value in the response will be True, and the NextPartNumberMarker will indicate the starting point for the next query.  
    4> -   To retrieve more information about uploaded parts, use the PartNumberMarker parameter to fetch data in batches.  
  • Complete example

    Java
    1import android.app.Activity;
    2import android.os.Bundle;
    3import com.baidubce.BceClientException;
    4import com.baidubce.BceServiceException;
    5import com.baidubce.auth.DefaultBceCredentials;
    6import com.baidubce.demo.R;
    7import com.baidubce.services.bos.BosClient;
    8import com.baidubce.services.bos.BosClientConfiguration;
    9import com.baidubce.services.bos.model.ListPartsRequest;
    10import com.baidubce.services.bos.model.ListPartsResponse;
    11import com.baidubce.services.bos.model.PartSummary;
    12public class ExampleActivity extends Activity {
    13private String bucketName = <BucketName>;
    14private String objectKey = <ObjectKey>;
    15private String uploadId = <UploadId>;
    16@Override
    17protected void onCreate(Bundle savedInstanceState) {
    18    super.onCreate(savedInstanceState);
    19    setContentView(R.layout.activity_main);
    20    new Thread(new Runnable() {
    21        @Override
    22        public void run() {
    23            try {
    24                BosClientConfiguration config = new BosClientConfiguration();
    25                config.setCredentials(new DefaultBceCredentials(<AccessKeyID>, <SecretAccessKey>));
    26                config.setEndpoint(<EndPoint>);
    27                BosClient client = new BosClient(config);
    28                ListPartsRequest listPartsRequest = new ListPartsRequest(<BucketName>, <ObjectKey>, <UploadId>);
    29                listPartsRequest.setMaxParts(100);
    30                listPartsRequest.setPartNumberMarker(50);
    31 // Retrieve all uploaded part information
    32                 ListPartsResponse partListing = client.listParts(listPartsRequest);
    33 // Traverse all parts
    34                 for (PartSummary part : partListing.getParts()) {
    35                     System.out.println("PartNumber: " + part.getPartNumber() + " ETag: " + part.getETag());
    36                 }
    37            } catch (BceServiceException e) {
    38                System.out.println("Error ErrorCode: " + e.getErrorCode());
    39                System.out.println("Error RequestId: " + e.getRequestId());
    40                System.out.println("Error StatusCode: " + e.getStatusCode());
    41                System.out.println("Error ErrorType: " + e.getErrorType());
    42                System.out.println("Error Message: " + e.getMessage());
    43            } catch (BceClientException e) {
    44                System.out.println("Error Message: " + e.getMessage());
    45            }
    46        }
    47    }).start();
    48}}

Encapsulate multipart upload

In the Android SDK, BOS provides the putSuperObjectFromFile interface, which consolidates the three main methods for multipart uploads: initiateMultipartUpload, UploadPart, and completeMultipartUpload. Using this interface, users can complete a multipart upload with built-in support for progress synchronization callbacks.

  • Simple example:

    Java
    1File file = new File("/path/to/file.zip");
    2PutSuperObjectRequest request = new PutSuperObjectRequest(bucketName, objectKey, file);
    3bosClient.putSuperObjectFromFile(request);
  • Example: Set the part size to 2MB, the thread count to 4, and synchronize progress callbacks every 1,024 bytes

    Java
    1BosClientConfiguration config=new BosClientConfiguration();
    2config.setUploadSegmentPart(1024);
    3File file = new File("/path/to/file.zip");
    4PutSuperObjectRequest request = new PutSuperObjectRequest(bucketName, objectKey,
    5                                                          file, 1024 * 1024 * 2L, 4);
    6request.setProgressCallback(new BosProgressCallback<PutSuperObjectRequest>() {
    7    @Override
    8    public void onProgress(PutSuperObjectRequest request, long currentSize, long totalSize) {
    9        Log.e(currentSize + "", totalSize + "");
    10    }
    11});
    12bosClient.putSuperObjectFromFile(request);

Note:

  • By default, the part size is 5MB, the thread count is 5, and the progress callback period is every 2,048 bytes.
  • If a large file takes a long time to upload and the user wants to end the multipart upload, they can call the cancel() method in PutSuperObjectRequest.

Previous
Log
Next
Bucket management