Skip to content

Commit

Permalink
[Images] Added new Direct Creator Upload v2 (cloudflare#3397)
Browse files Browse the repository at this point in the history
* new content

* added image resizing size limit to faq

* removed api link

* refined text

* Apply suggestions from code review

Co-authored-by: Pedro Sousa <[email protected]>

* removed "Content-Type" from curl
indented json

* rephrased endpoint

Co-authored-by: Pedro Sousa <[email protected]>
  • Loading branch information
marciocloudflare and pedrosousa authored Feb 9, 2022
1 parent 9d065f7 commit 313a51b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ To request a one-time upload URL, simply have your back-end (or Worker script) c

```bash
curl --request POST \
--url https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/images/v1/direct_upload \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer :token'
--url https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/images/v2/direct_upload \
--header 'Authorization: Bearer :token' \
--form 'requireSignedURLs=true' \
--form 'metadata={"key":"value"}'
```

You will receive a response similar to this:

```json
{
"result": {
"id": "2cdc28f0-017a-49c4-9ed7-87056c839c2",
"uploadURL": "https://upload.imagedelivery.net/2cdc28f0-017a-49c4-9ed7-87056c839c2"
"id": "2cdc28f0-017a-49c4-9ed7-87056c83901",
"uploadURL": "https://upload.imagedelivery.net/2cdc28f0-017a-49c4-9ed7-87056c83901"
},
"result_info": null,
"success": true,
Expand All @@ -31,29 +32,70 @@ You will receive a response similar to this:
}
```

Your back-end endpoint should return the `uploadURL` property to the client enabling it to upload the image without needing to pass any authentication information with it. Here is a simple HTML page that takes a one-time upload URL and uploads any selected image:
In the example above, `id` is a future image identifier that will be uploaded by a creator.

<Aside type="note" header="Note">

Previously, in version 1 of the `direct_upload` endpoint, the ID was an identifier of a request, not an image. Therefore, there was no way to know if an image had been really uploaded.

</Aside>

With version 2 of `direct_upload`, a new draft image record is created when you invoke this endpoint. It will not appear on a [list of images](https://api.cloudflare.com/#cloudflare-images-list-images ), but it is possible to fetch an image record with the provided ID to check its current status:

```bash
curl --url https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/images/v1/2cdc28f0-017a-49c4-9ed7-87056c83901 \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer :token'
```

You will receive a response similar to this:

```json
{
"result": {
"id": "2cdc28f0-017a-49c4-9ed7-87056c83901",
"metadata": {
"key": "value":
},
"uploaded": "2022-01-31T16:39:28.458Z",
"requiredSignedURLs": true,
"variants": [
"https://imagedelivery.net/Vi7wi5KSItxGFsWRG2Us6Q/2cdc28f0-017a-49c4-9ed7-87056c83901/public",
"https://imagedelivery.net/Vi7wi5KSItxGFsWRG2Us6Q/2cdc28f0-017a-49c4-9ed7-87056c83901/thumbnail"
],
"draft": true
},
"success": true,
"errors": [],
"messages": []
}
```

Once the image data is uploaded, the `draft` property will change to `false` and will not be part of the response anymore.

Your back-end endpoint should return the `uploadURL` property to the client, enabling it to upload the image without needing to pass any authentication information with it. Here is an example of a simple HTML page that takes a one-time upload URL and uploads any image the user selects:

```html
<html>
<body>
<form
action="INSERT_UPLOAD_URL_HERE"
method="post"
enctype="multipart/form-data"
>
<input type="file" id="myFile" name="file" />
<input type="submit" />
</form>
</body>
<body>
<form
action="INSERT_UPLOAD_URL_HERE"
method="put"
enctype="multipart/form-data"
>
<input type="file" id="myFile" name="file" />
<input type="submit" />
</form>
</body>
</html>
```

By default, the `uploadURL` will expire after 30 minutes if unused.

If you want to override this option, add the following argument to the cURL command:
To override this option, add the following argument to the cURL command:

```bash
--data '{"expiry":"2021-09-14T16:00:00Z"}'
--data '{"expiry":"2021-09-14T16:00:00Z"}'
```

The expiry value must be a minimum of two minutes and maximum of six hours in the future.
4 changes: 4 additions & 0 deletions products/images/src/content/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ Yes. Based on the `Accept` HTTP request header Cloudflare Images will be served

Refer to our [Plans](https://www.cloudflare.com/plans/) page for up-to-date information on pricing.

### Is there a limit on image size or file size for Image Resizing?

Yes. Maximum image size is 100 megapixels (for example, 10,000×10,000 pixels large). Maximum file size is 70 MB. GIF animations are limited to 100 megapixels total (sum of sizes of all frames).

### Resizing failed and I received an error response with a code. What does it mean?

Refer to [Troubleshoot Image Resizing problems](https://support.cloudflare.com/hc/articles/4412024022029) for more information on how to troubleshoot some of the more common issues, including error responses.
Expand Down

0 comments on commit 313a51b

Please sign in to comment.