menu button

API process flow

Get Upload URL

Upload an Audio/Video File

Before you can import an audio or video file into a project, you must generate a secure upload URL. This URL allows you to upload a file directly to Amazon S3 via a pre-signed POST request.

You can generate the upload URL using the getUploadUrl query.

Query Information

Supported File Types

You can upload the following file extensions: .mp3, .mp4, .wav, .mkv, .webm, .ogg, .m4a, .aac, .opus, .wma

uniqueObjName Requirements:

  • Must be a random 30-character alphanumeric string
  • Must end with the file extension
  • Example: [NAME].ogg

Budget Requirement The query will only succeed if the authenticated user (identified by the API Key) has sufficient remaining budget.

GraphQL Query (Get Upload URL)

fragment awsUrlObject on AWSUrlObject {
  url
  fields
}

query GetUploadUrl($uniqueObjName: String!) {
  getUploadUrl(uniqueObjName: $uniqueObjName) {
    ...awsUrlObject
  }
}

Example JS Code: Fetch the Upload URL

import axios from "axios";

export const GET_UPLOAD_URL = `...`;

const fetchUploadUrl = async () => {
  try {
    const response = await axios({
      method: "POST",
      url: "https://api-v2.speechmind.com/external/v2/graphql",
      headers: {
        "Content-Type": "application/json",
        "x-api-key": process.env.VUE_APP_API_KEY,
      },
      data: JSON.stringify({
        query: GET_UPLOAD_URL,
        variables: { uniqueObjName: "[NAME].ogg" },
      }),
    });

    const { url, fields } = response.data.data.getUploadUrl;
    console.log("Upload URL:", url);
    console.log("Fields:", fields);
  } catch (error) {
    console.error("Error fetching upload URL:", error);
  }
};

fetchUploadUrl();

Only working for budget to use

If the return value is None then your organization has not enough budget or no active subscription to upload more files.

Upload the File to S3

Once you have the pre-signed URL and fields, you can upload the file directly to S3.

AWS Response Structure

const { url, fields } = response.data.data.getUploadUrl;

Example cURL Upload Remember to replace each placeholder with values from your actual getUploadUrl response.

curl --location 'https://your-bucket-name.s3.amazonaws.com/' \
  --form 'key="UNIQUE_FILE_NAME"' \
  --form 'x-amz-algorithm="AWS4-HMAC-SHA256"' \
  --form 'x-amz-credential="FROM_RESPONSE"' \
  --form 'x-amz-date="FROM_RESPONSE"' \
  --form 'policy="FROM_RESPONSE"' \
  --form 'x-amz-signature="FROM_RESPONSE"' \
  --form 'file=@"<path-to-local-file>.ogg"'

Example JS Implementation for Uploading to S3

import axios from "axios";

async function uploadAudioToAWS(url, fileBlob, fields, fileName) {
  // Build FormData with AWS POST fields
  const formData = new FormData();
  Object.keys(fields).forEach((key) => {
    formData.append(key, fields[key]);
  });

  // Append the actual file
  const file = new File([fileBlob], fileName, {
    type: "audio/ogg",
  });
  formData.append("file", file);

  try {
    const response = await axios.post(url, formData, {
      headers: { "Content-Type": "multipart/form-data" },
    });

    console.log("File uploaded successfully:", response.data);
  } catch (error) {
    console.error("Error uploading file:", error);
  }
}

URL Expiration

The pre-signed upload URL is:

  • Valid only for one file
  • Valid for 5 minutes After expiration, you must request a new upload URL.

Have questions?

Still have questions? Talk to support.