Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

GET Object

Updated on 2023-11-09 GMT+08:00

API Description

You can use this API to download an object in a specified bucket.

Method Definition

1. ObsClient->getObject(array $parameter)
2. ObsClient->getObjectAsync(array $parameter, callable $callback)

Request Parameter

Field

Type

Optional or Mandatory

Description

Bucket

string

Mandatory

Bucket name

Key

string

Mandatory

Object name

VersionId

string

Optional

Object version ID

IfMatch

string

Optional

Returns the source object if its ETag is the same as the one specified by this parameter; otherwise, an exception is thrown.

IfModifiedSince

string

or

\DateTime

Optional

Returns the object if it is modified after the time specified by this parameter; otherwise, an exception is thrown. If this parameter value is a character string, it must conform to the HTTP time format specified in http://www.ietf.org/rfc/rfc2616.txt.

IfNoneMatch

string

Optional

Returns the source object if its ETag is different from the one specified by this parameter; otherwise, an exception is thrown.

IfUnmodifiedSince

string

or

\DateTime

Optional

Returns the object if it remains unchanged since the time specified by this parameter; otherwise, an exception is thrown. If this parameter value is a character string, it must conform to the HTTP time format specified in http://www.ietf.org/rfc/rfc2616.txt.

Range

string

Optional

Download range. The value range is [0, object length-1] and is in the format of bytes = x-y. The maximum length of Range is the length of the object minus 1. If it exceeds this value, the length of the object minus 1 is used.

Origin

string

Optional

Origin of the cross-domain request specified by the pre-request. Generally, it is a domain name.

RequestHeader

string

Optional

HTTP header in a cross-domain request

ResponseCacheControl

string

Optional

Rewrites the Cache-Control header in the response.

ResponseContentDisposition

string

Optional

Rewrites the Content-Disposition header in the response.

ResponseContentEncoding

string

Optional

Rewrites the Content-Encoding header in the response.

ResponseContentLanguage

string

Optional

Rewrites the Content-Language header in the response.

ResponseContentType

string

Optional

Rewrites the Content-Type header in the response.

ResponseExpires

string

Optional

Rewrites the Expires header in the response.

ImageProcess

string

Optional

Image processing parameter

SaveAsFile

string

Optional

Target path to which the object is downloaded (containing the file name)

SaveAsStream

boolean

Optional

Whether to return the object in the format of data stream

FilePath

string

Optional

Target path to which the object is downloaded (containing the file name). This is a deprecated parameter and is used to maintain compatibility with earlier versions.

SseC

string

Optional

Algorithm used in SSE-C decryption. The value can be:

  • AES256

SseCKey

string

Optional

Key used in SSE-C decryption, which is calculated by using AES-256.

NOTE:
  • If SaveAsStream is true, it cannot be used with SaveAsFile or FilePath.
  • SaveAsFile and FilePath cannot be used together.
  • If the download request includes IfUnmodifiedSince or IfMatch and IfUnmodifiedSince or IfMatch is not met, an exception will be thrown with HTTP status code 412 Precondition Failed.
  • If the download request includes IfModifiedSince or IfNoneMatch and IfModifiedSince or IfNoneMatch is not met, an exception will be thrown with HTTP status code 304 Not Modified.

Returned Result

Field

Type

Description

HttpStatusCode

integer

HTTP status code

Reason

string

Reason description

RequestId

string

Request ID returned by the OBS server

DeleteMarker

boolean

Whether the deleted object is a delete marker

LastModified

string

Time when the last modification was made to the object

ContentLength

integer

Object size in bytes

CacheControl

string

Cache-Control header in the response

ContentDisposition

string

Content-Disposition header in the response

ContentEncoding

string

Content-Encoding header in the response

ContentLanguage

string

Content-Language header in the response

ContentType

string

MIME type of the object

Expires

string

Expires header in the response

ETag

string

Object ETag

VersionId

string

Object version ID

WebsiteRedirectLocation

string

Location where the object is redirected to, when the bucket is configured with website hosting.

StorageClass

string

Storage class of the object. When the storage class is STANDARD, the value is null.

Restore

string

Restore status of the object in the OBS Archive storage class

AllowOrigin

string

If Origin in the request meets the CORS rules of the bucket, AllowedOrigin in the CORS rules is returned.

AllowHeader

string

If RequestHeader in the request meets the CORS rules of the bucket, AllowedHeader in the CORS rules is returned.

AllowMethod

string

AllowedMethod in the CORS rules of the bucket

ExposeHeader

string

ExposeHeader in the CORS rules of the bucket

MaxAgeSeconds

string

MaxAgeSeconds in the CORS rules of the bucket

SseKms

string

Algorithm used in SSE-KMS decryption

SseKmsKey

string

Master key used in SSE-KMS decryption

SseC

string

Algorithm used in SSE-C decryption

SseCKeyMd5

string

MD5 value of the key used in SSE-C decryption

Expiration

string

Expiration details

Body

GuzzleHttp\Psr7\Stream

Object content. If SaveAsFile is set, this field is null. If SaveAsStream is set to true, this field is a readable stream. You need to call the GuzzleHttp\Psr7\Stream->read method to read the data.

SaveAsFile

string

Target path to which the object is downloaded (containing the file name), which is consistent with that set in the request

Metadata

associative array

Customized metadata of the object

Sample Code

try{
       $resp = $obsClient -> getObject([
              'Bucket' => 'bucketname',
              'Key' => 'objectkey',
//            'SaveAsFile' => 'localfile',
//            'SaveAsStream' => true,
              'Range' => 'bytes=0-10'
       ]);
       printf("RequestId:%s\n", $resp['RequestId']);
       printf("ETag:%s\n", $resp['ETag']);
       printf("VersionId:%s\n", $resp['VersionId']);
       printf("StorageClass:%s\n", $resp['StorageClass']);
       printf("ContentLength:%s\n", $resp['ContentLength']);
       printf("DeleteMarker:%s\n", $resp['DeleteMarker']);
       printf("LastModified:%s\n", $resp['LastModified']);
       printf("Body:%s\n", $resp['Body']);
       printf("Metadata:%s\n", print_r($resp['Metadata'], true));
}catch (Obs\Common\ObsException $obsException){
       printf("ExceptionCode:%s\n", $obsException->getExceptionCode());
       printf("ExceptionMessage:%s\n", $obsException->getExceptionMessage());
}

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback