How to delete files within a folder from digitalocean in node.js

Viewed 16

I can upload a file within a folder in digitalocean spaces using the AWS SDK using the following:

const params = {
        Bucket: "my-bucket-name",
        Key: "test/" + 'sample.png',
        Body: image.data,
    };
    s3.putObject({ ...params, ACL: "public-read" }, (err, data) => {
        if (err) console.log(err);
        else console.log(data);
    });

Now I want to delete the file 'sample.png' without deleting the folder 'test' from the space. I tried the following snippet which deletes the entire folder:

const params = {
        Bucket: "my-bucket-name",
        Key: "test/sample.png",
    };

    s3.deleteObject({ ...params }, (err, data) => {
        if (err) console.log(err);
        else console.log(data);
    });
0 Answers
Related