There are many ways to pass files to JigsawStack APIs. This page will cover the most common methods, going from the easiest to the most complex.

1. Passing files through URLs

The easiest way to pass files to JigsawStack APIs is to pass in your file url. APIs that support file will always support url parameter. Here are a few examples straight from our API Reference.
import { JigsawStack } from "jigsawstack";

const jigsaw = JigsawStack({ apiKey: "your-api-key" });

const response = await jigsaw.vision.vocr({
  "url": "https://jigsawstack.com/preview/vocr-example.jpg"
  "prompt": [
        "total_price",
        "tax"
  ],
})

2. Passing the files using File Store

The second way to pass files to JigsawStack APIs is to use the file_store_key parameter. This is useful when you want to pass the same file to multiple APIs.

Upload the File to JigsawStack File Store

import { JigsawStack } from "jigsawstack";

const jigsaw = JigsawStack({
  apiKey: "your-api-key",
});

const imageFetch = await fetch("https://jigsawstack.com/preview/vocr-example.jpg");
const blob = await imageFetch.blob();

const response = await jigsaw.store.upload(blob, {
  overwrite: true,
  temp_public_url: true,
});

// Response:
// {'key': 'generated-file-store-key',
//  'size': 152856,
//  'temp_public_url': 'temp-public-url-to-the-file',
//  'url': 'url-to-the-file'
// }

Then pass the file_store_key to your desired API

const result = await jigsaw.vision.vocr({
  file_store_key: "generated-file-store-key",
});
You can access the preview link of the file by using the temp_public_url.
The temp_public_url is a temporary URL that will expire after 7 days.

3. Passing files directly

You can pass files directly to the API. This is useful if you dont want to encode the file as base64 or url.
import { JigsawStack } from "jigsawstack";

const jigsaw = JigsawStack({ apiKey: "your-api-key" });

const file = await fetch("https://jigsawstack.com/preview/vocr-example.jpg");
const fileBlob = await file.blob();

const response = await jigsaw.vision.vocr(fileBlob, {
  prompt: ["total_price", "tax"],
});

4. Passing files as multipart/form-data

By passing it as multipart/form-data, JigsawStack will handle the file encoding and pass the file to the API.
curl -X POST \
  -H "x-api-key: your-api-key" \
  -F "file=@/path/to/downloaded/image.jpg" \
  -F "body={\"prompt\": [\"total_price\", \"tax\"]}" \
  https://api.jigsawstack.com/v1/vocr