Uploading images from url

Hi, I am a pretty new developer so excuse me if this seems like a simple question.
Ive been trying to automate the uploading of images to a friends catalog, i have the URL of the images but no matter what i try i run into different errors.
I was able to succesfully run the “template” provided on the square site, and i thought that i would just need to either pass the URL directly, or worse case scenario just Fetch the file and pass it as a blob or similar, however i have been unable to make it happen.
I ran into many different errors from " The “path” argument must be of type string or an instance of Buffer or URL" to “an absolute URL error”.

Does anyone have any tips on how to approach this?

:wave: With the Catalog API uploading an image from a URL isn’t currently available. The image number, size, and format limitations are as follows:

  • An image can use the JPEG, PJPEG, PNG, or GIF format.
  • An image file cannot be larger than 250 MB.
  • There can be no more than 250 images attached to an image-supporting object.
  • There can be no more than 10,000 unattached images per Square account.
  • There can be no more than 5 million images per Square account.
    :slightly_smiling_face:

Hi @himochi You can send it as a blob.

I did it like this:

async function createCatalogImage(imageData) {
  try {
    const response = await fetch(imageData[0].url);
    const image = await response.blob();

    let formData = new FormData();
    formData.append("image", image, imageData[0].filename);
    formData.append(
      "request",
      JSON.stringify({
        idempotency_key: createIdempotencyKey(),
        is_primary: true,
        image: {
          type: "IMAGE",
          id: "#1",
          image_data: {
            name: imageData[0].filename,
            caption: imageData[0].filename,
          },
        },
      })
    );

    const newCatalogImage = await makeRequest(
      squareSandbox,
      createCatalogImgPath,
      "POST",
      token,
      formData
    );

    return newCatalogImage.image.id;
  } catch (error) {
    console.log(error);
    throw Error(error);
  }
}

The thing is that you need to send it as Form Data.

Hope that helps!