Introduction

The 3 Clicks file API enables developers to interact with the 3 Clicks filesystem programatically.

Concept

  1. User sends a request to 3 Clicks server

  2. 3 Clicks server creates a data entry for this request in the database and returns an AWS s3 upload policy to user

  3. User uses this policy directly upload to AWS s3 bucket. When done, give 3 Clicks server a callback

  4. 3 Clicks server update this upload request status to done

Key points

  • User will upload a file directly to AWS S3, not to 3 Clicks server.

  • Upload can be done by HTML/js, PHP, or any other language support aws s3 API. In our example, we use HTML/js

  • End-user browser can be replaced by some other server-side script as well, doesn't have to be a browser.

  • User needs some program to talk to 3 Clicks API first. In our example, we use PHP as user side server script.

Related parties

  • [3 Clicks Server]: generate AWS S3 policy, initialize upload request

  • [AWS S3]: file storage

  • [Your Server]: talk to 3 Clicks server to get the S3 policy, has 3 Clicks API key/secret, talke to end-user browser

  • [End-User Browser(or other server-side script)]: actual file upload

File Upload Example

Please use ApiUploadFileDemo.7z for this example

You can rewrite demo server-side code or end-user code with the language you prefer, as long as it can send the right HTTP API talk with 3 Clicks server, can talk to aws S3 API.

ApiUploadFileDemo.7z
225.5 KB

Server Side Setup

  • unzip ApiUploadFileDemo.7z to a server with php 7.4 support

  • update config with your own 3 Clicks API key/secret

How to use Html PageHTML

  1. Open the demo page (replace with your own domain and path)

  2. Select upload target: order or style.

  3. Fill target item number (order number/style number)

  4. Select file and click upload button

How Tech Details work

There are three api talk sessions between your script and 3 Clicks Cloud server.

  1. From your server side to 3 Clicks server, get s3 url and aws access id.

  2. When the end-user click upload button, your script will talk to 3 Clicks server to get s3 policy parameters. Now the end-user will upload file to aws s3 directly.

  3. When end-user file upload is complete the end-user html page will fire a callback to your server script, your script will talk to 3 Clicks server, let 3 Clicks know file upload has been successfully completed.