How to Generate a Signed URL for File Upload and Use it to Upload a File
Step 1: Generate a Signed URL for File Upload
To upload a file to a storage service, a signed URL allows you to securely upload the file directly. Here's how you generate the signed URL:
-
API Endpoint:
Make aPOST
request to the API endpoint:
https://api.pictory.ai/pictoryapis/v1/media/generateurl
-
Request Body:
Include the file name and content type in the request payload:{ "fileName": "sample1.mp3", "contentType": "audio/mpeg" }
-
Response:
If successful, the API will return a signed URL, file URL, and file key in the following format:{ "success": true, "data": { "signedUrl": "https://pictory-api-prod.s3.us-east-2.amazonaws.com/tyo789345-c46a-4a75-a8c9-0a3be59yurtc456/sample1.mp3?...", "url": "https://pictory-api-prod.s3.us-east-2.amazonaws.com/tyo789345-c46a-4a75-a8c9-0a3be59yurtc456/sample1.mp3", "key": "tyo789345-c46a-4a75-a8c9-0a3be59yurtc456/sample1.mp3" } }
Step 2: Use the Signed URL to Upload the File
Once you have the signed URL, you can use it to upload your file to the storage service.
-
Upload File with curl:
Use the signed URL in aPUT
request to upload the file. Here’s an examplecurl
command:curl --location --request PUT 'https://pictory-api-prod.s3.us-east-2.amazonaws.com/tyo789345-c46a-4a75-a8c9-0a3be59yurtc456/sample1.mp3?...' \ --header 'Content-Type: audio/mpeg' \ --data-binary '@/voices/Sample1.mp3'
-
Request Details:
- Replace the signed URL with the
signedUrl
from Step 1. - Set the
Content-Type
header to match the file type (e.g.,audio/mpeg
). - Use the
--data-binary
flag to upload the file, providing the path to your local file (e.g.,@/voices/Sample1.mp3
).
- Replace the signed URL with the
-
Response:
If successful, the API will return a200 OK
status. -
Access the File:
The uploaded file can be accessed using theurl
provided in the response from Step 1:
https://pictory-api-prod.s3.us-east-2.amazonaws.com/tyo789345-c46a-4a75-a8c9-0a3be59yurtc456/sample1.mp3
You can also refer to the examples provided by AWS documentation here
https://docs.aws.amazon.com/AmazonS3/latest/API/s3_example_s3_Scenario_PresignedUrl_section.html