From 5c0744b190880df7c31ffa93e7e66ce888188ad5 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 19 Mar 2024 21:39:58 +0000 Subject: [PATCH] feat(api): update via SDK Studio (#175) --- README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/README.md b/README.md index c6bf9d012b..acac923140 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,36 @@ main(); Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors. +## File Uploads + +Request parameters that correspond to file uploads can be passed in many different forms: + +- `File` (or an object with the same structure) +- a `fetch` `Response` (or an object with the same structure) +- an `fs.ReadStream` +- the return value of our `toFile` helper + +```ts +import fs from 'fs'; +import fetch from 'node-fetch'; +import Cloudflare, { toFile } from 'cloudflare'; + +const cloudflare = new Cloudflare(); + +// If you have access to Node `fs` we recommend using `fs.createReadStream()`: +await cloudflare.images.v1.create({ account_id: '023e105f4ecef8ad9ca31a8372d0c353' }); + +// Or if you have the web `File` API you can pass a `File` instance: +await cloudflare.images.v1.create({ account_id: '023e105f4ecef8ad9ca31a8372d0c353' }); + +// You can also pass a `fetch` `Response`: +await cloudflare.images.v1.create({ account_id: '023e105f4ecef8ad9ca31a8372d0c353' }); + +// Finally, if none of the above are convenient, you can use our `toFile` helper: +await cloudflare.images.v1.create({ account_id: '023e105f4ecef8ad9ca31a8372d0c353' }); +await cloudflare.images.v1.create({ account_id: '023e105f4ecef8ad9ca31a8372d0c353' }); +``` + ## Handling errors When the library is unable to connect to the API,