This topic was translated by AI and is currently in queue for revision by our editors. Alibaba Cloud does not guarantee the accuracy of AI-translated content. Request expedited revision

GetObject

Updated at: 2025-02-18 17:52

GetObject is used to retrieve a file (object). You must have read permissions on the object to call this operation.

Notes

  • By default, the GetObject operation supports access over HTTP and HTTPS. To allow access only over HTTPS, configure a bucket policy to specify the access method. For more information, see authorize users to access specified resources through bucket policy.

  • If the object is of the Archive type, you must send a RestoreObject request to restore the object or enable real-time access of Archive objects for the bucket in which the Archive object is stored.

Permission description

By default, an Alibaba Cloud account has full permissions. RAM users or RAM roles under an Alibaba Cloud account have no permissions by default. The Alibaba Cloud account or account administrator must grant permissions through RAM policy or bucket policy.

API

Action

Description

API

Action

Description

GetObject

oss:GetObject

Download an object.

oss:GetObjectVersion

When downloading an object, if the version of the object is specified by versionId, you need to grant permissions for this operation.

Versioning

By default, the GetObject operation returns only the current version of the object.

If a version ID of the object is specified in the request, OSS returns the specified version of the object. If the version ID is set to null, OSS returns the version of the object whose version ID is null.

Request syntax

GET /ObjectName HTTP/1.1
Host: BucketName.oss-cn-hangzhou.aliyuncs.com
Date: GMT Date
Authorization: SignatureValue
Range: bytes=ByteRange (optional)

For more information about how to calculate the Authorization header, see how to calculate the Authorization field.

If you download an object larger than 100 MB from OSS, the object may fail to download due to network errors. You can specify the Range header to query part of the content of the large object. For more examples of how to use the HTTP Range header to obtain OSS resources in segments, see how to obtain OSS resources in segments by using the HTTP Range header.

Request headers

When you initiate a GET request in OSS, you can set headers in the request to customize headers in the response. However, the headers in the response are set to the values specified in the headers in the request only if the request is successful. If the request is successful, 200 OK is returned.

Note

When you initiate a GET request as an anonymous user, you cannot set request headers to customize response headers.

Name

Type

Required

Description

Name

Type

Required

Description

Range

String

No

The range of data that you want to obtain.

  • If the specified range is valid, the total size of the object and the range of data are returned. For example, Content-Range: bytes 0~9/44 indicates that the total size of the object is 44 bytes, and the range of data to be returned is the first 9 bytes.

  • However, if the specified range is invalid, the entire object is returned, and the response does not include the Content-Range header.

Default value: null

If-Modified-Since

String

No

If the time specified in this header is earlier than the last modified time of the object or is invalid, the object and 200 OK are returned. Otherwise, 304 Not Modified is returned.

Time format: GMT, for example, Fri, 13 Nov 2015 14:47:53 GMT

Default value: null

If-Unmodified-Since

String

No

If the time specified in this header is the same as or later than the last modified time of the object, the object and 200 OK are returned. Otherwise, 412 Precondition Failed is returned.

Time format: GMT, for example, Fri, 13 Nov 2015 14:47:53 GMT

If-Modified-Since and If-Unmodified-Since can be used together.

Default value: null

If-Match

String

No

If the ETag specified in this header matches the ETag of the object, the object and 200 OK are returned. Otherwise, 412 Precondition Failed is returned.

The ETag value of an object is used to check whether the content of the object has changed. You can check data integrity by using the ETag value.

Default value: null

If-None-Match

String

No

If the ETag specified in this header does not match the ETag of the object, the object and 200 OK are returned. Otherwise, 304 Not Modified is returned.

If-Match and If-None-Match can be used together.

Default value: null

Accept-Encoding

String

No

The encoding type at the client side.

If you want an object to be returned in the GZIP format, you must include the Accept-Encoding:gzip header in your request.

OSS determines whether to compress data during transmission based on the Content-Type and size (at least 1 KB) of the object. If the conditions are met, the data is transmitted in a compressed format. Otherwise, the data is transmitted in its original format.

Note
  • If GZIP compression is used and takes effect, the ETag and Content-Length information is not included.

  • Currently, OSS supports GZIP compression for the following Content-Type types: text/cache-manifest, text/xml, text/css, text/html, text/plain, application/javascript, application/x-javascript, application/rss+xml, application/json, text/json.

Default value: null

Request parameters

Name

Type

Required

Description

Name

Type

Required

Description

response-content-language

String

No

The content-language header to be returned in the response.

Default value: null

response-expires

String

No

The expires header to be returned in the response.

Default value: null

response-cache-control

String

No

The cache-control header to be returned in the response.

Default value: null

response-content-disposition

String

No

The content-disposition header to be returned in the response.

Default value: null

response-content-encoding

String

No

The content-encoding header to be returned in the response.

Default value: null

Response headers

If the requested object is a symbolic link, the content of the object to which the symbolic link points is returned. The Content-Length, ETag, and Content-Md5 headers are the metadata of the object to which the symbolic link points. The Last-Modified header is the later of the last modified time of the object to which the symbolic link points and the last modified time of the symbolic link. Other headers are the metadata of the symbolic link.

Name

Type

Description

Name

Type

Description

x-oss-server-side-encryption

String

If the requested object is encrypted by using a server-side encryption algorithm based on entropy encoding, OSS automatically decrypts the object and returns the decrypted object after OSS receives the GetObject request. The x-oss-server-side-encryption header is included in the response to indicate the encryption algorithm used to encrypt the object on the server.

x-oss-tagging-count

String

The number of tags added to the object. This header is returned only if you have read permissions on tags.

x-oss-expiration

String

The expiration time of the object in the bucket for which lifecycle rules are configured.

  • Versioning enabled for the bucket

    • Version ID not included in the request

      If the object requested matches the delete conditions specified in the lifecycle rule, the x-oss-expiration header is included in the response to indicate the expiration time of the current version of the object.

    • Version ID included in the request

      The x-oss-expiration header is not included in the response regardless of whether the object requested matches the delete conditions specified in the lifecycle rule.

  • Versioning not enabled for the bucket

    • If the object requested matches the delete conditions specified in the lifecycle rule, the x-oss-expiration header is included in the response.

    • If the object requested does not match the delete conditions specified in the lifecycle rule, the x-oss-expiration header is not included in the response.

Examples

  • Simple GetObject Request

    Request Example

    GET /oss.jpg HTTP/1.1
    Host: oss-example.oss-cn-hangzhou.aliyuncs.com
    Date: Fri, 24 Feb 2012 06:38:30 GMT
    Authorization: OSS qn6q**************:77Dv****************

    Sample Response (when the object is a file)

    HTTP/1.1 200 OK
    x-oss-request-id: 3a8f-2e2d-7965-3ff9-51c875b*****
    x-oss-object-type: Normal
    Date: Fri, 24 Feb 2012 06:38:30 GMT
    Last-Modified: Fri, 24 Feb 2012 06:07:48 GMT
    ETag: "5B3C1A2E0563E1B002CC607C*****"
    Content-Type: image/jpg
    Content-Length: 344606
    Server: AliyunOSS
    [344606 bytes of object data]

    Sample Response (when the object is a directory)

    Important

    If the object is a directory and the request includes custom response headers such as Range, the custom response headers are invalid.

    HTTP/1.1 200 OK
    x-oss-request-id: 3a8f-2e2d-7965-3ff9-51c875b*****
    x-oss-object-type: Normal
    Date: Wed, 31 Mar 2021 06:38:30 GMT
    Last-Modified: Tue, 30 Mar 2021 06:07:48 GMT
    ETag: "null"
    Content-Type: application/x-directory
    Content-Length: 0
    Server: AliyunOSS
  • GetObject Request with Range Header

    Request Example

    GET /oss.jpg HTTP/1.1
    Host:oss-example.oss-cn-hangzhou.aliyuncs.com
    Date: Fri, 28 Feb 2012 05:38:42 GMT
    Range: bytes=100-900
    Authorization: OSS qn6q**************:77Dv****************

    Sample Response

    HTTP/1.1 206 Partial Content
    x-oss-request-id: 28f6-15ea-8224-234e-c0ce407*****
    x-oss-object-type: Normal
    Date: Fri, 28 Feb 2012 05:38:42 GMT
    Last-Modified: Fri, 24 Feb 2012 06:07:48 GMT
    ETag: "5B3C1A2E05E1B002CC607C*****"
    Accept-Ranges: bytes
    Content-Range: bytes 100-900/344606
    Content-Type: image/jpg
    Content-Length: 801
    Server: AliyunOSS
    [801 bytes of object data]
  • GetObject Request with Custom Response Headers

    Request Example

    GET /oss.jpg?response-expires=Thu%2C%2001%20Feb%202012%2017%3A00%3A00%20GMT&response-cache-control=No-cache&response-content-disposition=attachment%253B%2520filename%253Dtesting.txt&response-content-encoding=utf-8&response-content-language=%E4%B8%AD%E6%96%87 HTTP/1.1
    Host: oss-example.oss-cn-hangzhou.aliyuncs.com:
    Date: Fri, 24 Feb 2012 06:09:48 GMT

    Sample Response

    HTTP/1.1 200 OK
    x-oss-request-id: 559CC9BDC75A644*****
    x-oss-object-type: Normal
    Date: Fri, 24 Feb 2012 06:09:48 GMT 
    Last-Modified: Fri, 24 Feb 2012 06:07:48 GMT
    ETag: "5B3C1A2E053D1B002CC607*****"
    Content-Length: 344606
    Connection: keep-alive
    Content-disposition: attachment; filename=testing.txt
    Content-language: 中文
    Content-type: jpg
    Cache-control: no-cache
    Expires: Fri, 24 Feb 2012 17:00:00 GMT
    Server: AliyunOSS
    [344606 bytes of object data]
  • GetObject Request for a Symbolic Link

    Request Example

    GET /link-to-oss.jpg HTTP/1.1
    Accept-Encoding: identity
    Date: Tue, 08 Nov 2016 03:17:58 GMT
    Host: oss-example.oss-cn-hangzhou.aliyuncs.com
    Authorization: OSS qn6q**************:77Dv****************

    Sample Response

    HTTP/1.1 200 OK
    Server: AliyunOSS
    Date: Tue, 08 Nov 2016 03:17:58 GMT
    Content-Type: application/octet-stream
    Content-Length: 20
    Connection: keep-alive
    x-oss-request-id: 582143E6A212AD*****
    Accept-Ranges: bytes
    ETag: "8086265EFC021F9A2F09BF4****"
    Last-Modified: Tue, 08 Nov 2016 03:17:58 GMT
    x-oss-object-type: Symlink
    Content-MD5: gIYmXvwCEe0fmi8Jv0Y****
  • RestoreObject Request Completed

    Request Example

    GET /oss.jpg HTTP/1.1
    Host: oss-archive-example.oss-cn-hangzhou.aliyuncs.com
    Date: Sat, 15 Apr 2017 09:38:30 GMT
    Authorization: OSS qn6q**************:77Dv****************

    Sample Response

    HTTP/1.1 200 OK
    x-oss-request-id: 58F723829F29F18D7F00*****
    x-oss-object-type: Normal
    x-oss-restore: ongoing-request="false", expiry-date="Sun, 16 Apr 2017 08:12:33 GMT"
    Date: Sat, 15 Apr 2017 09:38:30 GMT
    Last-Modified: Sat, 15 Apr 2017 06:07:48 GMT
    ETag: "5B3C1A2E0763E1B002CC607C*****"
    Content-Type: image/jpg
    Content-Length: 344606
    Server: AliyunOSS
    [354606 bytes of object data]
  • GetObject Request with Specified Version ID

    Request Example

    GET /example?versionId=CAEQNhiBgMDJgZCA0BYiIDc4MGZjZGI2OTBjOTRmNTE5NmU5NmFhZjhjYmY0**** HTTP/1.1
    Host: versioning-get.oss-cn-hangzhou.aliyuncs.com
    Date: Tue, 09 Apr 2019 02:58:06 GMT
    Authorization: OSS qn6q**************:77Dv****************

    Sample Response

    HTTP/1.1 200 OK
    x-oss-request-id: 5CAC0A3EDE0170*****
    x-oss-version-id: CAEQNhiBgM0BYiIDc4MGZjZGI2OTBjOTRmNTE5NmU5NmFhZjhjYmY*****
    x-oss-object-type: Normal
    Date: Tue, 09 Apr 2019 02:58:06 GMT
    Last-Modified: Fri, 22 Mar 2018 08:07:50 GMT
    ETag: "5B3C1A2E053D7002CC607C5A*****"
    Content-Type: text/html
    Content-Length: 362149
    Server: AliyunOSS
    [362149 bytes of object data]
  • GetObject Request for an Object with a Delete Marker and No Specified Version ID

    Request Example

    GET /example HTTP/1.1
    Host: versioning-get.oss-cn-hangzhou.aliyuncs.com
    Date: Tue, 09 Apr 2019 03:22:33 GMT
    Authorization: OSS qn6q**************:77Dv****************

    Sample Response

    HTTP/1.1 404 Not Found
    x-oss-request-id: 5CAC0FEADE0170*****
    x-oss-delete-marker: true
    x-oss-version-id: CAEQNxiBgyA0BYiIDc4ZDdmNTA2MGViZTRiNjE5NzZlZWM4OWM5OT*****
    Date: Tue, 09 Apr 2019 03:22:33 GMT
    Content-Type: application/xml
    Connection: keep-alive
    Server: AliyunOSS
    <?xml version="1.0" encoding="UTF-8"?>
    <Error>
      <Code>NoSuchKey</Code>
      <Message>The specified key does not exist.</Message>
      <RequestId>5CAC0FEADE0170*****</RequestId>
      <HostId>versioning-get.oss-cn-hangzhou.aliyun*****</HostId>
      <Key>example</Key>
    </Error>
  • GetObject Request for an Object with a Specified Version ID and a Delete Marker

    Request Example

    GET /example?versionId=CAEQMxiBgMCfqaWA0BYiIDliMWI4MGQ0MTVmMjQ3MmE5MDNlMmY4YmFkYTk3**** HTTP/1.1
    Host: versioning-get.oss-cn-hangzhou.aliyuncs.com
    Date: Tue, 09 Apr 2019 03:09:44 GMT
    Authorization: OSS qn6q**************:77Dv****************

    Sample Response

    HTTP/1.1 405 Method Not Allowed
    x-oss-request-id: 5CAC0CF8DE01700*****
    x-oss-delete-marker: true
    x-oss-version-id: CAEQMxiBgMCfqaWADliMWI4MGQ0MTVmMjQ3MmE5MDNlMmY4YmFkYTk*****
    Allow: DELETE
    Date: Tue, 09 Apr 2019 03:09:44 GMT
    Content-Type: application/xml
    Content-Length: 318
    Connection: keep-alive
    Server: AliyunOSS
    <?xml version="1.0" encoding="UTF-8"?>
    <Error>
      <Code>MethodNotAllowed</Code>
      <Message>The specified method is not allowed against this resource.</Message>
      <RequestId>5CAC0CF8DE0170*****</RequestId>
      <HostId>versioning-get.oss-cn-hangzhou.aliyun*****</HostId>
      <Method>GET</Method>
      <ResourceType>DeleteMarker</ResourceType>
    </Error>

SDK

OSS SDKs for the following programming languages are available to call the GetObject operation:

Command line tool ossutil

For more information about the ossutil command that corresponds to the GetObject operation, see get-object.

Error codes

Error code

HTTP status code

Description

Error code

HTTP status code

Description

NoSuchKey

404

The specified object does not exist.

SymlinkTargetNotExist

404

The requested object is a symbolic link, and the object to which the symbolic link points does not exist.

InvalidTargetType

400

The requested object is a symbolic link, and the object to which the symbolic link points is another symbolic link.

InvalidObjectState

403

The error message returned because the following scenarios occur when the storage class of the object is Archive:

  • The RestoreObject request for the object was not initiated or timed out.

  • The RestoreObject request for the object has been initiated but the object is not restored yet.

Not Modified

304

The error message returned due to the following possible causes:

  • The If-Modified-Since header is specified, but the object is not modified after the specified time.

  • The If-None-Match header is specified, and the ETag of the object is the same as the value specified in this header.

Precondition Failed

412

The error message returned due to the following possible causes:

  • The If-Unmodified-Since header is specified, but the specified time is earlier than the last modified time of the object.

  • The If-Match header is specified, but the ETag of the object is different from the value specified in this header.

Not Found

404

The error message returned because the version ID of the object is not specified in the request and the current version of the object is a delete marker.

Method Not Allowed

405

The error message returned because the version ID of the object is specified in the request and the version is a delete marker.

  • On this page (1)
  • Notes
  • Permission description
  • Versioning
  • Request syntax
  • Request headers
  • Request parameters
  • Response headers
  • Examples
  • SDK
  • Command line tool ossutil
  • Error codes
Feedback