• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. Developer Guide (Python SDK)
  4. Object Upload
  5. Performing a Streaming Upload

Performing a Streaming Upload

Streaming upload uses readable objects that contain the read property as data sources. Sample code is as follows:

Uploading a Network Stream

# 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'
)

import sys
if sys.version_info.major == 2 or not sys.version > '3':
    import httplib
else:
    import http.client as httplib

conn = httplib.HTTPConnection('www.a.com', 80)
conn.request('GET', '/')
content = conn.getresponse()

resp = obsClient.putContent('bucketname', 'objectkey', content=content)

if resp.status < 300:    
    print('requestId:', resp.requestId)
else:    
    print('errorCode:', resp.errorCode)
    print('errorMessage:', resp.errorMessage)

Uploading a File Stream

# 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'
)
content = open('localfile', 'rb')

resp = obsClient.putContent('bucketname', 'objectkey', content=content)

if resp.status < 300:    
    print('requestId:', resp.requestId)
else:    
    print('errorCode:', resp.errorCode)
    print('errorMessage:', resp.errorMessage)
  • When this upload mode is used, the value of content must be a readable object that contains the read property.
  • When uploading file streams, you must open files in rb or rb+ mode.
  • To upload a large file, you are advised to use multipart upload.