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:

  1. API Endpoint:
    Make a POST request to the API endpoint:
    https://api.pictory.ai/pictoryapis/v1/media/generateurl

  2. Request Body:
    Include the file name and content type in the request payload:

    {
      "fileName": "sample1.mp3",
      "contentType": "audio/mpeg"
    }
    
  3. 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.

  1. Upload File with curl:
    Use the signed URL in a PUT request to upload the file. Here’s an example curl 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'
    
    
  2. 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).
  3. Response:
    If successful, the API will return a 200 OK status.

  4. Access the File:
    The uploaded file can be accessed using the url 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


Try request here

Language
Click Try It! to start a request and see the response here!