By repkam09
How do I create a signed public ‘share’ URL similar to the ‘Quick Share’ option in Spaces?
I am writing an application in Node.JS and would like to return a temporary access URL to the user so they can access a file stored in spaces for a set amount of time. The Space itself is set to Private and the files are all Private as well, so just giving a direct URL to them isn’t possible.
The DigitalOcean UI already has this “Quick Share” feature, but there doesn’t seem to be any documentation about what its doing to create that URL and I cant figure out how to sign the request correctly to generate one myself.
The URL parameters in question are, AWSAccessKeyId, Expires and Signature. The AWSAccessKeyId and Expires seem simple enough, but how do I go about calculating the signature?
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!
Accepted Answer
The AWS signature formats can be a bit complicated. Though the reason for making Spaces compatible with the S3 API is that there are already quite a few tools that can work with it. If you’re working with Node, I’d encourage you to use one of the existing libraries.
The aws-sdk-js can help generate these “pre-signed” URLs. Here’s a quick basic example of it’s usage:
const AWS = require('aws-sdk')
const spacesEndpoint = new AWS.Endpoint('nyc3.digitaloceanspaces.com');
const s3 = new AWS.S3({
endpoint: spacesEndpoint,
accessKeyId: 'ACCESSKEY',
secretAccessKey: 'SECRETKEY'
});
const bucket = 'my-bucket-name'
const key = 'my-file-name.ext'
const expireSeconds = 60 * 5
const url = s3.getSignedUrl('getObject', {
Bucket: bucket,
Key: key,
Expires: expireSeconds
})
console.log(url)
I hope no one minds me ressurecting this thread…
Does the approach above, where you use the existing AWS libraries to generate a URL, mean you could just use that S3 URL and transform it according to a certain pattern (ex. substitute AWS domain for DO domain etc) and use that new URL to download/upload objects from/to Spaces?
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.