Uploading Objects - Browser-Based
API Description
You can use this API to upload objects to a specified bucket in HTML form. The maximum size of an object is 5 GB. You can call ObsClient.createPostSignature to generate request parameters for browser-based upload. You can use code to simulate a browser-based upload. For details, see post_object_sample. You can also perform a browser-based upload as follows:
- Call ObsClient.createPostSignature to generate request parameters for authentication.
- Prepare an HTML form page.
- Enter the request parameters in the HTML page.
- Select a local file and upload it in browser-based mode.
There are two request parameters generated:
- policy, which corresponds to the policy field in the form
- signature: corresponds to the signature field in the form.
Method Definition
ObsClient.createPostSignature(bucketName, objectKey, expires, formParams)
Request Parameters
|
Field |
Type |
Optional or Mandatory |
Description |
|---|---|---|---|
|
bucketName |
str |
Optional |
Bucket name |
|
objectKey |
str |
Optional |
Object name, which corresponds to the key field in the form. |
|
expires |
int |
Optional |
Validity period of the browser-based upload authentication, in seconds. The default value is 300. |
|
formParams |
dict |
Optional |
Other parameters of the browser-based upload except for key, policy, and signature. Possible values are:
|
Returned Results
|
Field |
Type |
Description |
|---|---|---|
|
originPolicy |
str |
Value of policy that is not Base64 encoded. This parameter can only be used for verification. |
|
policy |
str |
policy in the form |
|
signature |
str |
signature in the form |
Sample Code
try:
# Set parameters for the form.
formParams = {}
# Set the object ACL to public-read.
formParams['x-obs-acl'] = 'public-read'
# Set the MIME type for the object.
formParams['content-type'] = 'text/plain'
# Set the validity period for the browser-based upload request, in seconds.
resp = obsClient.createPostSignature(expires=3600, formParams=formParams)
# Obtain the request parameters.
print('\t', resp['policy'])
print('\t', resp['signature'])
except:
import traceback
print(traceback.format_exc())
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form action="http://bucketname.your-endpoint/" method="post" enctype="multipart/form-data">
<p>
Object key
</p>
<!-- Object name -->
<input type="text" name="key" value="objectname" />
<p>
ACL
</p>
<!-- Object ACL permission -->
<input type="text" name="x-obs-acl" value="public-read" />
<p>
Content-Type
</p>
<!-- MIME type of the object -->
<input type="text" name="content-type" value="text/plain" />
<p>
<!-- Base64 code of the policy -->
<input type="hidden" name="policy" value="*** Provide your policy ***" />
<!-- AK -->
<input type="hidden" name="AccessKeyId" value="*** Provide your access key ***"/>
<!-- Signature string information -->
<input type="hidden" name="signature" value="*** Provide your signature ***"/>
<input name="file" type="file" />
<input name="submit" value="Upload" type="submit" />
</p>
</form>
</body>
</html>
- Values of policy and signature in the HTML form are obtained from the returned result of ObsClient.createPostSignature.
- You can directly download the HTML form example PostDemo.
Last Article: Uploading an Object – Obtaining the Upload Progress
Next Article: Object Download Overview
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.