Uploading Data from a Web Client to OBS and Setting an Upload Callback
Scenarios
As shown in Figure 1, files are commonly uploaded through a browser to the app server and then uploaded to OBS. Data transfer on the app server results in a low efficiency. Moreover, the app server will be heavily loaded if multiple tasks are concurrently uploaded.
This section describes how to use the PostObject API to directly upload a file from a web client to OBS and set an upload callback, which is called form-based upload. After the upload is successful, the specified address will receive a callback. Solution Architecture shows the solution architecture of form-based upload. In this solution, a file is directly uploaded from a web client to OBS without being transferred through the app server. This makes the transfer faster and does not impose pressure on the server. Additionally, using a signature returned by the server makes direct transfer more secure.
Solution Architecture

The following describes the process of uploading a file from a web client to OBS and setting an upload callback:
- A user sends a request to the server through the web client to obtain an upload security policy.
- The server calculates the signature using the security credentials and upload security policy, and returns the upload security policy and signature to the web client.
- The user uses the HTML form constructed on the web client to upload a file to OBS and set an upload callback.
- OBS sends a callback request to the server.
- The server returns a response to OBS.
- OBS returns the upload result to the web client.

A security policy defines which content can be uploaded using a form. For example, you can specify in a policy that only objects whose name starts with prefix01 can be uploaded using a form.
Resource Planning
Region |
Resource |
Resource Name |
Description |
Quantity |
Billing |
---|---|---|---|---|---|
CN North-Beijing4 |
OBS bucket |
post-callback-demo |
The bucket used to store the uploaded file You need to create a bucket on OBS Console. |
1 |
You will be billed for the storage space occupied by the file. For details, see Storage Space. |
- |
File |
demo-object.txt |
The file to be uploaded You need to prepare the file to be uploaded in advance. |
1 |
- |
- |
AK/SK pair |
AK/SK |
The credential for accessing OBS. The server uses the AK/SK pair to generate a signature for user authentication. For details about AKs and SKs, see Access Keys. |
1 |
- |
Operation Process
To upload a file from a web client to OBS and set an upload callback, do as follows:
- Create a bucket and configure a CORS rule: Create a bucket on OBS Console for storing the uploaded file. Configure a cross-origin resource sharing (CORS) rule for the bucket to allow cross-origin access from the web client.
- Request a signature from the server: Request the server to generate a signature. The signature is generated using the security credentials and upload policy (with the bucket name, object name prefix, expiration time, and others included), which authorizes you to complete the file upload within a specified time.
- Upload a file using a form and set an upload callback: Construct a POST request in an HTML form on the web client and set an upload callback.
Procedure
Verification
The HTML form contains a file selection box and an upload button. You can select the file to be uploaded and submit the form.
When the form is submitted, JavaScript sends a request to the server to obtain the required signature and callback information. Once a valid response is received, the FormData object is constructed and populated with all required data. A POST request is then made to the OBS server using the fetch method to complete the file upload. Once the upload succeeds, a callback is triggered to the address specified by callbackUrl.
Upload the demo-object file to bucket post-callback-demo using the form. If the demo-object file can be found in the bucket post-callback-demo, the file is successfully uploaded.

Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot