File Upload Guide

A common initial question we get is how to provide the document_url field in our API when our users are dealing with local files.

Upload and Generate Presigned URL with AWS S3

import boto3

# Create an S3 client
s3 = boto3.client("s3")

# Open the local file in binary read mode
with open("./sample.pdf", "rb") as file:
    # Upload the file to the specified S3 bucket
    s3.put_object(Body=file, Bucket="BUCKET_NAME", Key="sample.pdf")

# Generate a pre-signed URL for the uploaded file
url = s3.generate_presigned_url(
    "get_object",
    Params={"Bucket": "BUCKET_NAME", "Key": "sample.pdf"},
    ExpiresIn=3600,
)

print(url)