Report this

What is the reason for this report?

automatic content-disposition header pre-setup on uploaded media files

Posted on August 31, 2020

I have a space for my droplet, and i use to setup the metadata of my uploaded media file, so for me to setup content-disposition header on those media files, i have to either select and set it up one by one or mark maybe 50 or more and then go to manage metadata and set it’s content-disposition header to anything i want.

But my media files are too much now, so i have to track the newly uploaded files and set them one after the other which is very confusing and stressful.

Please is there any way to pre-set the metadata of files in a digital ocean space, so if i upload any file it will automatically have it’s metadata setup ones it is uploaded.

if there is a way pls i really need help.



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!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello,

As of the time being the DigitalOcean Spaces does not provide built-in support to automatically set or modify metadata like Content-Disposition upon file upload. However, there are some workarounds that can be used:

  1. Use Spaces SDK or API: You can use DigitalOcean’s Spaces SDKs (for example, AWS S3 SDK because Spaces is S3-compatible) or REST API to upload files. This way, you can set the Content-Disposition (or any other headers) when you upload the file. This gives you full control over the upload process and metadata. Note that this may require changing how you upload files to your Space.

Here is an example using AWS SDK for JavaScript:

const AWS = require('aws-sdk');

const spacesEndpoint = new AWS.Endpoint('nyc3.digitaloceanspaces.com');
const s3 = new AWS.S3({
    endpoint: spacesEndpoint,
    accessKeyId: 'your-access-key',
    secretAccessKey: 'your-secret-key'
});

const params = {
    Body: "Hello", // Replace with your file's data
    Bucket: 'your-bucket-name',
    Key: 'your-file-name',
    ContentType: 'text/plain', // Replace with your file's mime type
    ContentDisposition: 'attachment; filename="filename.txt"' // Replace with your desired content-disposition
};

s3.putObject(params, function(err, data) {
    if (err) console.log(err, err.stack);
    else     console.log(data);
});
  1. Create a Worker or a Script: You can create a worker or a script that runs periodically (or on upload), identifies newly uploaded files and then updates their metadata to include Content-Disposition. This script would use Spaces API as well.

Best,

Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.