Strapi Upload service cannot handle Buffers

System Information
  • Strapi Version: 3.6.1
  • Operating System: nixos-20.09 & platform.sh
  • Database: sqlite & postgres
  • Node Version: 12.21.0
  • NPM Version: 6.14.11
  • Yarn Version: 1.22.5

Hi,

Upon trying to revive the strapi-plugin-import-content - see related forum post I found out that the enhanceFile method of the Strapi Upload service throws an error when passing in a Buffer instead of a File object. The reason being that this function assumes that all objects passed to fs.readFile have a path attribute.

I’ve created a PR that shows the change I made to make the Upload service work with Buffer’s as well

Spoiler:
readBuffer = await util.promisify(fs.readFile)(file && file.path || file);
instead of
readBuffer = await util.promisify(fs.readFile)(file.path);

Kind regards,

Erik aka 4levels

2 Likes