Baidu AI Cloud
中国站

百度智能云

Object Storage

PostObject

Interface Description

This interface uploads files to the specified bucket through the HTML form, which is used to upload files to the bucket through the browser. The parameters are passed through the HTTP request header during PutObject and passed through the form field in the message body during PostObject. The message body is encoded in the multipart/form-data format.

Request

  • Request syntax

POST / HTTP/1.1 
Host: BucketName.bj.bcebos.com
Content-Length:<ContentLength>
orage-class: <StorageClass>
Date:<date>
Content-Type: multipart/form-data; boundary=<boundary>

--<boundary>
Content-Disposition: form-data; name="accessKey"

499d0610679c4da2a69b64086a4cc3bc
--<boundary>
Content-Disposition: form-data; name="policy"

eyJleHBpcmF0aW9uIjoiMjAxNy0wMS0yOFQxMDo1NjoxOVoiLCJjb25kaXRpb25zIjpbWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsIDMwMDAwMDAwLCA0MDAwMDAwMF0sIHsia2V5IjogImFiKiJ9LCB7ImJ1Y2tldCI6ICJib3MxMDAtZGVidWcifV19
--<boundary>
Content-Disposition: form-data; name="signature"

d1a617a725122c203195fe22ed9c4d20406ee259df8552e3f5344c3e1db84afe
--<boundary>
Content-Disposition: form-data; name="key"

test_object_name
--<boundary>
Content-Disposition: form-data; name="Content-Disposition"

attachment;filename="download/object"
--<boundary>
Content-Disposition: form-data; name="x-bce-meta-object-tag"

test1
--<boundary>
Content-Disposition: form-data; name="success-redirect-url"

http://demo.test.com/upload_success?object=test_object&bucket=test_bucket&time=xxx&userid=xxx
--<boundary>
Content-Disposition: form-data; name="file"; filename="upload_file"
Content-Type: text/plain

i'm test file content.
--<boundary>--
  • Request parameters

Terms Type Description Required?
accessKey String User AccessKey Optional
Cache-Control, Content-Type, Content-Disposition, Expires String It uploads the headers supported by the object. Such headers are set during the upload and returned during the download. Optional
file - The text content uploaded must be the last field in the form. If there are other fields after the file, they are ignored. Yes
key String It uploads the object name. If there is no this field, an error occurs. Yes
policy String The policy describes the limit conditions of the form. The anonymous request without policy can only access the public read-write buckets. The policy must be in the Base64 format, whose maximum size is limited to 4,096 characters. For the policy format, see the description below the table. Optional
signature String The signature is the signature information calculated according to the secret key and policy. BOS verifies the signature to verify the legitimacy of the POST request. Optional
success-action-redirect String URL redirected after the successful upload -
success-action-status Int It can be 200, 201 or 204, 200 by default. When it is 201, the location field returns the object location. -
x-bce-meta-* String User-defined meta. Optional
x-bce-storage-class String It specifies the default storage type of object. STANDARD_IA represents the infrequent access, COLD represents the cold storage, and ARCHIVE represents the archive storage. If it is not specified, it is the standard storage by default. If it is a multi-AZ bucket, MAZ_STANDARD_IA represents the multi-AZ infrequent access. If it is not specified, it is the standard storage with multiple AZs by default and cannot be other values. Optional
x-bce-acl String Header supported by CannedACL, in which the user sets the permission of the object, whose value is private or public-read. No
x-bce-grant-read String Header supported by CannedACL, in which the user sets the read permission of the object. It supports multiple IDs separated by commas No
x-bce-grant-full-control String Header supported by CannedACL, in which the user sets the FULL_CONTROL permission of the object. It supports multiple IDs separated by commas No
x-bce-server-side-encryption String Server encryption algorithm, only AES256 is supported currently. No
x-bce-content-crc32 String It uploads the CRC (cyclic redundancy check) value of the object. No

The policy needs to be UTF-8 characters. You can set its expiration date and limit the bucket, key and file length. Only exact match can be carried out for the bucket, and the exact match and prefix match can be carried out for the object. The format is as follows:

 { "expiration": "2015-03-01T12:00:00Z",
   "conditions": [
        {
            "bucket": "testbucket" 
        },
        {
            "key": "testkey"
        }, // Exact match
        {
            "key": "testkey*"
        }, // Prefix match, it contains one and only one *, which can be put to the end only.
        ["content-length-range", 0, 4096]
   ]
 }

Considerations

  • PostObject must have the write permission of the bucket. The public read-write buckets do not need to upload the signature information. Otherwise, the signature needs to be verified. Unlike PutObject, PostObject uses SK corresponding to AK to sign the policy field after base64_encode as the signature, and BOS verifies the signature to check the validity of the user. The signature logic is signature = hmac.new(sk, base64.b64encode(policy), hashlib.sha256).hexdigest().
  • The key and file field of the entire form are required. If there are parameters other than parameter list above, an error InvalidArgument occurs.
  • If there is an authorization field in PostObject, BOS does not check it.
  • The submission form code for the PostObject operation must be “multipart/form-data”. Other formats are not supported, that is, Content-Type in the header is in the form of multipart/form-data; boundary=xxxxxx, and the boundary is the boundary string.
  • PostObject does not support the STS authentication.

Response

  • Response header field

    Name Type Description
    Content-MD5 String The MD5 digest of the HTTP request content defined in RFC2616 can be contained to verify whether the file saved in BOS is consistent with the user expected file.
    ETag String HTTP protocol entity tag of the object
  • Response parameters

    None

Example

  • Request example of standard storage

    POST / HTTP/1.1 
    Host: BucketName.bj.bcebos.com
    Content-Length:11434
    Date:Tue, 29 Mar 2016 12:00:00 GMT
    Content-Type: multipart/form-data; boundary=341261481596
    
    --341261481596
    Content-Disposition: form-data; name="accessKey"
    
    499d0610679c4da2a69b64086a4cc3bc
    --341261481596
    Content-Disposition: form-data; name="policy"
    
    eyJleHBpcmF0aW9uIjoiMjAxNy0wMS0yOFQxMDo1NjoxOVoiLCJjb25kaXRpb25zIjpbWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsIDMwMDAwMDAwLCA0MDAwMDAwMF0sIHsia2V5IjogImFiKiJ9LCB7ImJ1Y2tldCI6ICJib3MxMDAtZGVidWcifV19
    --341261481596
    Content-Disposition: form-data; name="signature"
    
    d1a617a725122c203195fe22ed9c4d20406ee259df8552e3f5344c3e1db84afe
    --341261481596
    Content-Disposition: form-data; name="key"
    
    test_object_name
    --341261481596
    Content-Disposition: form-data; name="Content-Disposition"
    
    attachment;filename="download/object"
    --341261481596
    Content-Disposition: form-data; name="x-bce-meta-object-tag"
    
    test1
    --341261481596
    Content-Disposition: form-data; name="success-redirect-url"
    
    http://demo.test.com/upload_success?object=test_object&bucket=test_bucket&time=xxx&userid=xxx
    --341261481596
    Content-Disposition: form-data; name="file"; filename="upload_file"
    Content-Type: text/plain
    
    i'm test file content.
    --341261481596--
  • Example of infrequent access/cold storage request

    POST / HTTP/1.1 
    Host: BucketName.bj.bcebos.com
    Content-Length:11434
    orage-class: STANDARD_IA 
    Date:Tue, 29 Mar 2016 12:00:00 GMT
    Content-Type: multipart/form-data; boundary=341261481596
    
    --341261481596
    Content-Disposition: form-data; name="accessKey"
    
    499d0610679c4da2a69b64086a4cc3bc
    --341261481596
    Content-Disposition: form-data; name="policy"
    
    eyJleHBpcmF0aW9uIjoiMjAxNy0wMS0yOFQxMDo1NjoxOVoiLCJjb25kaXRpb25zIjpbWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsIDMwMDAwMDAwLCA0MDAwMDAwMF0sIHsia2V5IjogImFiKiJ9LCB7ImJ1Y2tldCI6ICJib3MxMDAtZGVidWcifV19
    --341261481596
    Content-Disposition: form-data; name="signature"
    
    d1a617a725122c203195fe22ed9c4d20406ee259df8552e3f5344c3e1db84afe
    --341261481596
    Content-Disposition: form-data; name="key"
    
    test_object_name
    --341261481596
    Content-Disposition: form-data; name="Content-Disposition"
    
    attachment;filename="download/object"
    --341261481596
    Content-Disposition: form-data; name="x-bce-meta-object-tag"
    
    test1
    --341261481596
    Content-Disposition: form-data; name="success-redirect-url"
    
    http://demo.test.com/upload_success?object=test_object&bucket=test_bucket&time=xxx&userid=xxx
    --341261481596
    Content-Disposition: form-data; name="file"; filename="upload_file"
    Content-Type: text/plain
    
    i'm test file content.
    --341261481596--
  • Response example

    HTTP/1.1 200 OK
    x-bce-request-id: 4db2b34d-654d-4d8a-b49b-3049ca786409
    Date:Tue, 29 Mar 2016 12:00:00 GMT
    ETag: "1b2cf535f27731c974343645a3985328"
    Content-MD5: H2koac2M0YsMxDNte2XJ8A==
    Content-Length: 0
    Connection: close
    Server: BceBOS
Previous
GetObjectMeta
Next
PutObject