• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. Developer Guide (Python SDK)
  4. Object Download
  5. Rewriting Response Headers

Rewriting Response Headers

When downloading an object, you can rewrite some HTTP/HTTPS response headers. The following table lists rewritable response headers.

Parameter

Description

GetObjectRequest.content_type

Rewrites Content-Type in HTTP/HTTPS responses.

GetObjectRequest.content_language

Rewrites Content-Language in HTTP/HTTPS responses.

GetObjectRequest.expires

Rewrites Expires in HTTP/HTTPS responses.

GetObjectRequest.cache_control

Rewrites Cache-Control in HTTP/HTTPS responses.

GetObjectRequest.content_disposition

Rewrites Content-Disposition in HTTP/HTTPS responses.

GetObjectRequest.content_encoding

Rewrites Content-Encoding in HTTP/HTTPS responses.

Sample code:

# Import the module.
from com.obs.client.obs_client import ObsClient
# Create an instance of ObsClient.
obsClient = ObsClient(
    access_key_id='*** Provide your Access Key ***',    
    secret_access_key='*** Provide your Secret Key ***',    
    server='yourdomainname'
)

from com.obs.models.get_object_request import GetObjectRequest

getObjectRequest = GetObjectRequest()
getObjectRequest.content_type = 'image/jpeg'

resp = obsClient.getObject('bucketname', 'objectkey', loadStreamInMemory=True, getObjectRequest=getObjectRequest)
if resp.status < 300:
    print('requestId:', resp.requestId)
    # Obtain the rewritten response headers.
    print('contentType:', resp.body.contentType)
else:
    print('errorCode:', resp.errorCode)
    print('errorMessage:', resp.errorMessage)