If the folder doesn't exist sharp throws me an error
Is there's a way to sharp to create such folder if it doesn't exist?
.toFile(`./public/uploads/${'resize-' + req.body.file}`)
Error: vips__file_open_write: unable to open file "./public/uploads/greyscale-67badcb0-8a98-4126-828a-4e9fe152979b.jpeg" for writing
unix error: No such file or directory
Hello, please see #874.
@lovell got it. So you suggest something like this: first check is directory is exist, if not then create it with mkdirp and only after fire up sharp? Can I see basic clean example, because right now it looks little messed for me.
const mkdirp = require('mkdirp-promise');
const sharp = require('sharp');
(async () => {
await mkdirp('public/uploads');
await sharp()
// ...
.toFile(`./public/uploads/${'resize-' + req.body.file}`);
})();
@papandreou thanks!
Most helpful comment