# { "error": \[ "Error opening image. Check that you are sending a properly formatted image." \] }

**URL:** <https://discuss.roboflow.com/t/error-error-opening-image-check-that-you-are-sending-a-properly-formatted-image/1207>\
**Category:** 🤝  Community Help\
**Tags:** bugs\
**Created:** [December 25, 2022, 12:51am UTC](https://discuss.roboflow.com/t/error-error-opening-image-check-that-you-are-sending-a-properly-formatted-image/1207 "2022-12-25T00:51:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![deFED](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/defed/32/984_2.png) [@deFED](https://discuss.roboflow.com/u/deFED)\
**Post date:** [December 25, 2022, 12:51am UTC](https://discuss.roboflow.com/t/error-error-opening-image-check-that-you-are-sending-a-properly-formatted-image/1207/1 "2022-12-25T00:51:29Z")

</div>

This category is for question related to accounts on [https://app.roboflow.com/](https://app.roboflow.com/)

Please share the following so we may better assist you:

Hi I am trying to use the inference API with a base64 encoded image. After sending a base 64 image string through the API I get the following response:  
{ “error”: [“Error opening image. Check that you are sending a properly formatted image.”] }

Any thoughts on requestments for image formats send the the inference api?

Any one have luck using the roboflow API with with Flutterflow?

---

<div class="post-metadata">

**Author:** ![Mohamed](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/mohamed/32/62_2.png) [@Mohamed](https://discuss.roboflow.com/u/Mohamed)\
**Post date:** [December 25, 2022, 1:16am UTC](https://discuss.roboflow.com/t/error-error-opening-image-check-that-you-are-sending-a-properly-formatted-image/1207/2 "2022-12-25T01:16:29Z")

</div>

My initial hunch is the image size you’re sending.

Can you try resizing the image in your inference code (prior to sending it to the API) to the size you have preprocessed it to during version generation?

For example, if you resized to 416x416, resize the image to 416x416 pixels. If you selected 640x640 (or even if you haven’t resized), then set the image to 640x640.

Here’s an example in Python for sending a local image file (resized) to the API for inference:

- example of a roboflow\_config.json file: [roboflow-computer-vision-utilities/roboflow\_config.json at main · roboflow/roboflow-computer-vision-utilities · GitHub](https://github.com/roboflow/roboflow-computer-vision-utilities/blob/main/roboflow_config.json)

Note on the config file: you can omit “EMAIL”, “\_\_comment2”, “FRAMERATE”, and “BUFFER" from the file since they’re used only if you’re sending an email with the inference results or running this with a webcam.

```auto
import json
import cv2
import base64
import numpy as np
import requests
import time

# load config
with open('roboflow_config.json') as f:
    config = json.load(f)

    ROBOFLOW_API_KEY = config["ROBOFLOW_API_KEY"]
    ROBOFLOW_MODEL = config["ROBOFLOW_MODEL"]
    ROBOFLOW_SIZE = config["ROBOFLOW_SIZE"]

# Construct the Roboflow Infer URL
# (if running locally replace https://detect.roboflow.com/ with eg http://127.0.0.1:9001/)
upload_url = "".join([
    "https://detect.roboflow.com/",
    ROBOFLOW_MODEL,
    "?api_key=",
    ROBOFLOW_API_KEY,
    "&format=image",
    "&stroke=2"
])

# Infer via the Roboflow Hosted Inference API and return the result
def infer(img):
    # Resize (while maintaining the aspect ratio) to improve speed and save bandwidth
    height, width, channels = img.shape
    scale = ROBOFLOW_SIZE / max(height, width)
    img = cv2.resize(img, (round(scale * width), round(scale * height)))

    # Encode image to base64 string
    retval, buffer = cv2.imencode('.jpg', img)
    img_str = base64.b64encode(buffer)

    # Get prediction from Roboflow Infer API
    resp = requests.post(upload_url, data=img_str, headers={
        "Content-Type": "application/x-www-form-urlencoded"
    }, stream=True).raw

    # Parse result image
    image = np.asarray(bytearray(resp.read()), dtype="uint8")
    image = cv2.imdecode(image, cv2.IMREAD_COLOR)

    return image

img_file = cv2.imread(“INSERT_FILE_PATH”)
result = infer(img_file)

cv2.imshow(‘predictions’, result)

```

- [GitHub - roboflow/roboflow-api-snippets: repo for versioning snippets that show how to use Roboflow APIs](https://github.com/roboflow/roboflow-api-snippets) for examples in other code languages
- [JavaScript](https://github.com/roboflow/roboflow-api-snippets/tree/main/Javascript) and [Python](https://github.com/roboflow/roboflow-api-snippets/tree/main/Python) for quick access

---

<div class="post-metadata">

**Author:** ![Mohamed](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/mohamed/32/62_2.png) [@Mohamed](https://discuss.roboflow.com/u/Mohamed)\
**Post date:** [December 25, 2022, 1:21am UTC](https://discuss.roboflow.com/t/error-error-opening-image-check-that-you-are-sending-a-properly-formatted-image/1207/3 "2022-12-25T01:21:34Z")

</div>

Also dropping this here for others that see this, and are wondering where to find our API documentation:

- [Hosted API (Remote Server) - Roboflow](https://docs.roboflow.com/inference/hosted-api)
- [https://docs.roboflow.com/adding-data/upload-api](https://docs.roboflow.com/adding-data/upload-api)
- [Uploading Private Bucket Data - Roboflow](https://docs.roboflow.com/adding-data/uploading-private-bucket-data)
- [REST API - Roboflow](https://docs.roboflow.com/rest-api)
