lace-blobs-server-dev
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
index.ts
https://thesolarmonk--836cdc8a6d7611f09a2a0224a6c84d84.web.val.run
A simple S3 proxy service that generates signed URLs for uploading and downloading files from AWS S3.
You need to set the following environment variables in your Val Town settings:
AWS_ACCESS_KEY_ID- Your AWS access key IDAWS_SECRET_ACCESS_KEY- Your AWS secret access keyAWS_S3_BUCKET- The S3 bucket name to useAWS_REGION- AWS region (optional, defaults to us-east-1)
Your AWS credentials need the following S3 permissions:
s3:GetObjects3:PutObject
Generate a signed URL for uploading a file to S3.
Request:
{ "objectId": "my-file.jpg" }
Response:
{ "signedUrl": "https://bucket.s3.amazonaws.com/my-file.jpg?...", "objectId": "my-file.jpg", "expiresIn": 3600 }
Generate a signed URL for downloading a file from S3.
Request:
{ "objectId": "my-file.jpg" }
Response:
{ "signedUrl": "https://bucket.s3.amazonaws.com/my-file.jpg?...", "objectId": "my-file.jpg", "expiresIn": 3600 }
- Call
/uploadwith the desired object ID - Use the returned signed URL to PUT your file directly to S3
- The signed URL expires in 60 minutes
- Call
/downloadwith the object ID - Use the returned signed URL to GET the file directly from S3
- The signed URL expires in 60 minutes
The API returns appropriate HTTP status codes:
200- Success400- Bad request (missing objectId)500- Server error (missing config, AWS errors)