Question

How can I access private files on Spaces using GET?

Hi, I am trying to access private files from my Spaces, I have not found any way to access my files through the GET method. I have a secret and a key id, the standard credentials, are there any variables I can use in order to access my private files using my id and secret? For example, something like: {bucket-name}.{location}.digitaloceanspaces.com/PRIVATE-FILE?id={my-id}&secret={my-secret} I really need help with this, if it is not possible, please can someone instruct me on how to access private files using the aws-sdk. Thank you very much

Subscribe
Share

Submit an 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.

for those who get here without an answer, I managed to do it as follows…

Change getObject for getCommand, look:

$client = new Aws\S3\S3Client(
[
  'version' => 'latest',
  'region' => 'nyc3',
  'endpoint' => 'https://nyc3.digitaloceanspaces.com',
  'credentials' => [
                      'key' => 'myKey',
                      'secret' => 'mySecret',
                   ]
]);

$cmd = $client->getCommand('GetObject',
[
  'Bucket' => 'MyBucket',
  'Key' => 'FileName.pdf' (your file),
  'ResponseContentDisposition' => 'attachment; filename = "FileName.pdf'(your file)
]);

$request = $client->createPresignedRequest($cmd, '+5 minutes');
$preSignedUrl = (string) $ request-> getUri ();

header ('Location:'. $ preSignedUrl); //force dowload

while bumping on this question I was looking for to download a private file from my react application with node as a backend.

Here is how I acheived it.

    const spacesEndpoint = new AWS.Endpoint(process.env.END_POINT);
    const s3 = new AWS.S3({
        endpoint: spacesEndpoint,
        accessKeyId: process.env.AWS_ACCESS_KEY_ID,
        secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
    });

Then, generate a signed url for your file and send it to frontend.

  const url = s3.getSignedUrl('getObject', {
    Bucket: process.env.BUCKET_NAME,
    Key: `pdfs/exams/v1/sthrandom.pdf`,
  });
  res.send(url);

Hi there! I am having the same problem! Any solution??

Bumping this in the new year, as this hasn’t been answered quite well yet? Anyone can help?

Bumping this, I am having the same problem but cannot find an answer for it in Node.js/express.

I tried a few different libraries for generating an S4 signature (I have to confess I don’t understand how to do it myself, the instructions are just too unclear) and I keep getting a SignatureDoesNotMatch error. I wonder if part of the problem might be that those libraries are optimized for AWS, and not DO?

Hi, We are trying to access the Private files from Spaces using Elfinder File Manager. But not able to access when it is having Private Access. So we are not able to access unless we give them Public Access which is may not good for the application. If we give Public access people can access using URL through any browser without any permissions.

We are able to upload files to the Spaces also, but not able to access same file that we just uploaded. So we would like to upload/access the files with Private access through Elfinder File Manager.

Currently we are using S3 Adapter. Appreciate if any suggestions.

Thank you very much Venu Kommu

Spaces was designed to be compatible with the S3 API in order to allow users to leverage existing tools. Accessing private files requires generating a signature for authentication. As this is quite complicated, you should generally use an existing library in your programing language of choice.

Check out this question for examples in a number of languages:

Let us know more about how you are trying to access the files, and we can provide a more specific answer.