symphonicc / multer-azure-blob-storage

ES6 & Typescript friendly multer storage engine for Azure's blob storage.
MIT License
19 stars 25 forks source link

Using it with sharpjs #18

Closed ChiKaLiO closed 2 years ago

ChiKaLiO commented 4 years ago

This is question more then an issue I've spent the last 8 hours trying to figure it out..

const resolveMetadata = (req, file) => { return new Promise((resolve, reject) => { const metadata = sharp(file).resize(1000) .webp({quality: 80},{ progressive: true, force: false }); resolve(metadata); }); };

it just wont work lol ! console.log(file) prints null so i can't figure anything 😭

Sliverb commented 3 years ago

@ChiKaLiO I do not see anything wrong with your code. But without knowing much about how sharp works, maybe the call is meant to be async or you might want to just pass in the file stream into sharp vs the entire file obj

E.g.

// Async stuff
const resolveMetadata = (req, file) => {
    return new Promise((resolve, reject) => {
        sharp(file).resize(1000).webp({ quality: 80 }, { progressive: true, force: false })
            .then((metadata) => resolve(metadata))
            .catch((error) => reject(error));
    });
};

// Stream stuff
const resolveMetadata = (req, file) => {
    return new Promise((resolve, reject) => {
        const metadata = sharp(file.stream).resize(1000).webp({ quality: 80 }, { progressive: true, force: false });
        resolve(metadata);
    });
};

Are you still having this issue or did you figure it out?

Sliverb commented 2 years ago

Closing for now due to no response from @ChiKaLiO

Feel free to re-open if this comes up again