The ts-media-storage
sample application demonstrates how to use the @klotho::persist
annotation to store media files and serve them through a @klotho::expose
annotated applocation.
This guide assumes:
run the terminal commands:
npm install
npx ts-node index.ts
# hitting the / endpoint
curl localhost:3000/
# > Hello from Klotho!%
# Upload an image
curl -X POST 'http://localhost:3000/v1/images/myfile' --form 'image=@"path/to/your/image"'
# > Uploaded image to /tmp/myfile.png%
# Retrieve path for uploaded image by id
curl http://localhost:3000/v1/images/myfile
# > /tmp/myfile.png%
# Delete an image by id
curl http://localhost:3000/v1/images/myfile -X DELETE
run the terminal commands:
# Compile the app
npx tsc && klotho . --app ts-media-storage -p aws
# Go into the compiled directory
cd compiled
# If you didn't set the aws region as indicated in the compiler output, do that now
pulumi config set aws:region YOUR_REGION -s ts-media-storage
# npm install
npm install
# Deploy
pulumi up -s ts-media-storage
# Outputs: {
# apiUrl: 'https://<...>.execute-api.<YOUR_REGION>.amazonaws.com/stage/'
# }
# hitting the / endpoint
curl https://<...>.execute-api.<YOUR_REGION>.amazonaws.com/stage/
# > Hello from Klotho!%
# Upload an image
curl -X POST https://<...>.execute-api.<YOUR_REGION>.amazonaws.com/stage/v1/images/myfile --form 'image=@"path/to/your/image"'
# > Uploaded image to /tmp/myfile.png%
# Retrieve path for uploaded image by id
curl https://<...>.execute-api.<YOUR_REGION>.amazonaws.com/stage/v1/images/myfile
# > https://338991950301ts-media-storage-payloads.s3.amazonaws.com/files/tmp/myfile.png%
# Delete an image by id is not supported yet in the cloud
curl https://<...>.execute-api.<YOUR_REGION>.amazonaws.com/stage/v1/images/myfile -X DELETE
From the compiled directory still,
# Tear down when done
pulumi destroy -s ts-media-storage