Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
"Unrecognized content encoding type" error when uploading an image

I am trying to fetch images that I have uploaded to my CDN. I used canvas.toDataURL to convert my images to PNGs before upload.

I get the following error when I try to fetch the images: Error: cURL error 61: Unrecognized content encoding type. libcurl understands deflate, gzip, br content encodings

So first I created this image using FabricJS: Then I am exporting it as a PNG using:

const dataURL = canvas.toDataURL({
    width: canvas.width,
    height: canvas.height,
    left: 0,
    top: 0,
    format: 'png'
})

Then I am uploading it to my S3 CDN using:

async function uploadPNG(dataURL, filePath) {
  const buf = Buffer.from(dataURL.replace(/^data:image\/\w+;base64,/, ""),'base64')

  const uploadParams = {
    Bucket: bucketName,
    ContentType: 'image/png',
    ContentEncoding: 'base64',
    Body: buf,
    Key: filePath
  }

  return await s3.upload(uploadParams).promise()
}

Then I am trying to upload that image (which is now in the S3 CDN) to a WooCommerce site using their API. https://s3.eu-central-1.amazonaws.com/cdn.blankt.com/product/s/AY6AJSHMXnf2ReCZOu.png

Here is part of that API request:

{
  "name": "AY6AJSHMXnf2ReCZOu",
  "type": "variable",
  "regular_price": "9.90",
  "sku": "AY6AJSHMXnf2ReCZOu",

  ...

  ],
  "images": [
    {
      "src": "https://s3.eu-central-1.amazonaws.com/cdn.blankt.com/product/s/AY6AJSHMXnf2ReCZOu.png"
    }
  ],
  "attributes" : [
    {
      "name"      : "Size",
      "variation" : true,
      "visible"   : true,
      "options"   : [ "A3", "A4", "A5" ]
    }
  ]
}

And this is the response that I get: enter image description here

This problem seem to only appear when I try to upload the image using the API, if I download and upload the image manually to WooCommerce, there are no problems.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It would seem that you're providing the invalid content encoding in your s3 upload, where you provide the parameter ContentEncoding: 'base64'.

The s3 SDK documentation for the upload method is somewhat unclear in the specifics of handling the ContentEncoding parameter:

ContentEncoding — (String) Specifies what content encodings have been applied to the object and thus what decoding mechanisms must be applied to obtain the media-type referenced by the Content-Type header field.

But my suspicion is that it is simply passed along as the Content-Encoding HTTP header (MDN) when the object is accessed. In which case the image loads fine in your browser because it's smart (or perhaps dumb) enough to discard the encoding that it doesn't recognize, however WooCommerce's backend does not do that, and instead produces an error.

Solution: remove the ContentEncoding from your s3 upload params -- you're not uploading encoded content in the first place, since you decode the base64 data to raw bytes when you pass it to Buffer.from with the 'base64' encoding parameter (See Buffer.from(string[, encoding]) and character encodings in Node.JS docs)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!