Filebase
Search…
Create and Use Pre-Signed URLs with Filebase
Learn how to generate and use Pre-signed URLs with Filebase.

Pre-Signed URLS

With object storage, URLs are used to identify and access specific objects. To perform operations on objects within a private bucket, one must calculate and submit an authentication signature along with the request, which requires possession of an access key and secret access key. However, there are times when access to keys is not available. For these scenarios, a pre-signed URL can also be generated, which gives you access to perform operations on an object, but without the need to possess the access keys.
For example, you could generate a pre-signed URL to download an object from a private a bucket, and share that URL with another individual. This would grant the individual download access, without you having to share your access credentials with them.
Pre-signed URLs can also be utilized by users and customers to upload specific objects to private buckets.
It should also be noted that pre-signed URLs are only valid until the specified time and date. All actions, such as uploading and downloading objects, must be completed before the expiration time and date. A pre-signed URL can be used multiple times, as long as it is before the expiration time and date.

Pre-Signed URL Prerequisites:

  • Filebase Access and Secret Keys. Learn how to view your access keys here.
  • Filebase Bucket. Learn how to create and manage buckets here.
  • Object Key (File Name)
  • Expiration Time

Using AWS CLI to generate a pre-signed S3 URL

If you haven't used AWS CLI before, see here for our guide on configuring and getting started using AWS CLI.
To create a pre-signed URL with AWS CLI:
aws s3 --endpoint https://s3.filebase.com presign s3://filebase-bucket-name/file.name
This command should return a pre-signed URL. By default, the expiration time is one hour:
You can specify a different expiration time by adding the flag --expires-in followed by the number of minutes.

Using Python and Boto3 to generate a pre-signed S3 URL

This example for generating a pre-signed URL uses Python. You can generate pre-signed URLs for use with Java, JavaScript, Ruby, and .NET frameworks as well.

Additional Python and Boto3 Prerequisites:

1. Edit the code below to include your Filebase access key and secret key, then save the code as a .py file.

1
import boto3
2
import requests
3
import json
4
5
from botocore.config import Config
6
7
s3 = boto3.client('s3')
8
9
boto_config = Config(
10
region_name = 'us-east-1',
11
signature_version = 's3v4')
12
13
s3 = boto3.client(
14
's3',
15
endpoint_url = 'https://s3.filebase.com',
16
aws_access_key_id='FilebaseAccess-Key',
17
aws_secret_access_key='Filebase-Secret-Key',
18
config=boto_config)
19
20
bucket = input("Enter your Bucket Name: ")
21
key= input("Enter your desired object for this upload: ")
22
23
print (" Generating pre-signed url...")
24
25
response = s3.generate_presigned_url('put_object', Params={'Bucket':bucket,'Key':key}, ExpiresIn=3600, HttpMethod='PUT')
26
27
print (response)
28
29
if response is None:
30
exit(1)
31
32
response = requests.put(response)
33
34
print('PUT status_code: ', response.status_code)
35
print('PUT content: ', response.content)
Copied!
This example uses an expiration time of 3600 seconds.

2. In a terminal window, navigate to the directory where you saved the .py folder. Execute the python script.

3. Enter your bucket name and desired object name to upload.

4. The terminal will return a pre-signed URL as seen below. Copy this URL to your clipboard.

5. From the terminal, use the following curl command to upload any file to Filebase using the pre-signed URL:

1
curl --request PUT --upload-file <file-name> "<http://your-pre-signed-url>"
Copied!

6. Confirm that the file has been uploaded by checking the Filebase web console for your bucket.

Filebase does not upload 0 byte (empty) files. Files need to be more than 0 bytes for a successful file upload.
If you have any questions, please send us an email at [email protected].
Last modified 26d ago