> ## Documentation Index
> Fetch the complete documentation index at: https://jigsaw-13.mintlify.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Handling Files

> Learn how to pass files to JigsawStack APIs.

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](/docs/api-reference).

<CodeGroup>
  ```javascript vocr_url.js theme={null}
  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"
    ],
  })
  ```

  ```python vocr_url.py theme={null}
  from jigsawstack import JigsawStack

  jigsaw = JigsawStack(api_key="your-api-key")

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

## 2. Passing the files using [File Store](/docs/api-reference/store/file/add)

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

<CodeGroup>
  ```javascript file_upload.js theme={null}
  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'
  // }
  ```

  ```python file_upload.py theme={null}
  import requests
  from jigsawstack import JigsawStack

  jigsaw = JigsawStack(api_key="your-api-key")

  image_response = requests.get(
      "https://jigsawstack.com/preview/vocr-example.jpg"
  )
  blob = image_response.content

  response = 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'
  # }
  ```
</CodeGroup>

### Then pass the `file_store_key` to your desired API

<CodeGroup>
  ```javascript file_store_key.js theme={null}
  const result = await jigsaw.vision.vocr({
    file_store_key: "generated-file-store-key",
  });
  ```

  ```python file_store_key.py theme={null}
  result = jigsaw.vision.vocr({
      "file_store_key": "generated-file-store-key",
  });
  ```
</CodeGroup>

You can access the preview link of the file by using the `temp_public_url`.

<Warning>
  The `temp_public_url` is a temporary URL that will expire after 7 days.
</Warning>

## 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.

<CodeGroup>
  ```javascript vocr_direct.js  theme={null}
  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"],
  });
  ```

  ```python vocr_direct.py theme={null}
  from jigsawstack import JigsawStack
  import requests

  jigsaw = JigsawStack(
      api_key="<your-api-key>"
  )

  # Get the image from URL
  image_url = "https://jigsawstack.com/preview/vocr-example.jpg"
  image_response = requests.get(image_url)
  imageblob = image_response.content

  response = jigsaw.vision.vocr(
      imageblob,
      {"prompt": ["total_price", "tax"]},
  )

  print(response)
  ```
</CodeGroup>

## 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.

<CodeGroup>
  ```curl curl_example.sh theme={null}
  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
  ```

  ```javascript multipart_form_data.js theme={null}
  const file = await fetch("/path/to/downloaded/image.jpg");

  const body = {
    prompt: ["total_price", "tax"],
  }

  const formData = new FormData();
  formData.append("file", file);
  formData.append("body", JSON.stringify(body));

  const response = await fetch("https://api.jigsawstack.com/v1/vocr", {
    method: "POST",
    body: formData,
  });
  console.log(response);
  ```

  ```python multipart_form_data.py theme={null}
  import requests

  files = {
      "file": open("/path/to/downloaded/image.jpg", "rb"),
  }

  data = {
      "prompt": ["total_price", "tax"],
  }

  response = requests.post("https://api.jigsawstack.com/v1/vocr", files=files, data=data)
  print(response.json())
  ```
</CodeGroup>
