How to use a WriteStream to upload to DigitalOcean Spaces

Hi, I recently was using Google Cloud storage to store my objects and I was using a WriteStream in the following way:

const imgUpload = multer({
    storage: multer.memoryStorage(),
    fileFilter: (_, file: any, callback: FileFilterCallback) => {
        if (file.mimetype == "image/jpeg" || file.mimetype == "image/png") {
            callback(null, true);
        } else {
            callback(new Error("Not an image"));
    // @ts-ignore
    async (req: Request, res: Response) => {
        if (!req.file) {
            return res.status(500).json({ file: "No file received" });
        const name = await v4();
        const blob = postPicsBuckets.file(name);
        const blobStream = blob.createWriteStream({
            resumable: false,
            gzip: true,

        blobStream.on("error", (err) => {
            return res.status(500).json({ error: err.message });
        blobStream.on("finish", async () => {
            const publicUrl = `${}/${}`;
            await Post.create({
                imgUrl: publicUrl,
                creatorId: req.session.userId,
                description: req.body.description,
            res.status(200).send({ url: publicUrl });



can anybody please tell me how to do such a thing with DigitalOcean Spaces where I can upload the file in the callback function and not in the Multer config itself ?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer