Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

"Error uploading image with JavaScript client: Invalid image, could not read metadata"

1 replies
Last updated: Dec 26, 2022
ā€¢ OK It turns out that, I was sending the BLOB via URL to the function and that was the problem. Leaving the code here in case someone gets the same err.Hello, I am trying to upload an image with javascript client but getting the following error. Anybody gets the same error before? The blob is the File object where I get from react dropzone.


{
    "response": {
        "body": {
            "statusCode": 400,
            "error": "Bad Request",
            "message": "Invalid image, could not read metadata",
            "details": "Input buffer contains unsupported image format"
        },
        "url": "<https://xx.api.sanity.io/v2022-03-10/assets/images/production?filename=634ff16fea978807370a020d>",
        "method": "POST",
        "headers": {
            "content-length": "150",
            "content-type": "application/json; charset=utf-8",
            "etag": "W/\"96-wI2AUJgOZsmnCanyui4zXBV3NKg\""
        },
        "statusCode": 400,
        "statusMessage": ""
    },
    "statusCode": 400,
    "responseBody": "{\n  \"statusCode\": 400,\n  \"error\": \"Bad Request\",\n  \"message\": \"Invalid image, could not read metadata\",\n  \"details\": \"Input buffer contains unsupported image format\"\n}"
}

export async function uploadImageBlob(blob: File, fileName: string) {

    console.log(blob)

    client.assets.upload('image', blob, { contentType: 'image/jpeg', filename: fileName })
        .then(() => { console.log('upload success')})
        .catch((err) => { console.log(err)});

}
Dec 24, 2022, 8:18 PM
Hello
user G
you can always also publish something on our exchange , if you feel like it šŸ™‚ This way people will be able to find your snippet through google
Dec 26, 2022, 12:59 PM

Sanityā€“ build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?