Image upload guide

At the time of this writing, the API allows uploading images, fetching single or multiple images and updating images.

Uploading local image

This is the most basic way to upload an image to Hasty. This is a three-step process.

  • The first step is to generate signed URLs for your upload. This will return a list of upload IDs and URLs for uploading your image(s). Note that only one image can be uploaded to each URL. You can generate multiple URLs using this endpoint.

  • The next step is to upload your image to an URL. Here's the cURL command for this request:

    curl -X PUT --upload-file /path/to/image \
        -H "Content-Type: image/*"
  • Finally, you'll have to import the image to your project. When doing so, in addition to dataset_id, the upload_id (received in first step) and filename (name of the image in the project dataset) must be specified.

NOTE: File names for images must be unique in a dataset.

Uploading from URLs

Another option is to upload images directly from URLs, if your images are hosted somewhere online and are accessible publicly.

In this scenario, you can directly use the image upload endpoint. In addition to dataset_id, you can optionally specify filename. If filename is not specified, then the basename of the URL is used instead. You can also specify whether to copy the image to Hasty storage using copy_original flag. This is enabled by default. If this is disabled, then we only store temporary assets related to the image (such as thumbnails and labels), which are cleaned up and regenerated every now and then.

Additional notes if copying is disabled

If copying is disabled, then it's up to the user to make sure that the URL is accessible and has a valid image until the dataset or project or user data is removed. Expired URL, corrupted image, etc. may lead to unexpected behavior in the platform.

Also, the following headers must be set for accessing the images in the platform.

Access-Control-Allow-Methods: GET, HEAD, OPTIONS
Access-Control-Allow-Headers: Content-Type, Content-Length, Transfer-Encoding

Updating images

Images in projects can also be replaced using update image endpoint.

NOTE: You can't change the dataset the image belongs to.

You can optionally specify filename field in the request body to change the filename of the image.

Replacing an existing image is similar to the upload process detailed above. If your new image exists locally, then you can either a generate signed URL, upload the image and set the upload_id field in body, or if it's publicly accessible and has the right CORS rules, then you can directly import from that URL using url field (copy_original field can also be used here).