GET
/
media
/
uploadUrl
Available on Premium, Business, Enterprise plans.

For file uploads greater than 10 MB, obtain a presigned URL to upload a file.

  • Maximum file upload size 5 GB.
  • Upload presigned URL valid for 30 minutes after being generated.
  • Access URL available for 30 days after uploaded. All published posts are unaffected at the social networks. Scheduled posts beyond that time frame will result in errors at time of publishing.

Header Parameters

Authorization
string
required
Format: Authorization: Bearer API_KEY. See API overview for more information.

Query Parameters

fileName
string

If the contentType is not present, then a full file name with extension is required.

Name of the file to be uploaded. Must include an extension such as .png, .jpg, .mov, .mp4, etc.

contentType
string

The content-type of the media being uploaded. Valid formats include: mp4, quicktime, png, jpg, or jpeg.

If not present, application/octet-stream will be used.

Reponse Details

  • accessUrl is the URL to access the media file after upload.
  • contentType is the content-type set for the media being upload. Use this in the Content-Type header when uploading the media.
  • uploadUrl is the URL used to PUT the media file. Please see below.

Additional Endpoint Examples

The process to upload larger files:

  • Obtain an uploadURL and accessURL via the /media/uploadUrl endpoint. Please see above.
  • Upload the file via a PUT with Content-Type set to the returned contentType.
  • Upload the media by using the --upload-file with a media file and the uploadUrl.
  • After uploading the media file, POST to the /post endpoint with the accessUrl in the mediaUrls body parameter.
  • The presigned upload URL may only be uploaded to once. If you sent a bad file you must create a new upload URL. No error response will occur if the file is not successfully uploaded. See below of verifying the URL exists.

Please be sure that the contentType set when creating the uploadUrl matches the Content-Type and the file type when PUTing the file. For example, if you set the contentType to “image/png” when creating the uploadUrl, be sure to set the “Content-Type: image/png” and the uploaded file ends in “.png”.

Example Upload File Binary in Node.js

Here is an example of uploading a binary media file using Node with JavaScript:

const fs = require("fs");
const request = require("request");

const API_KEY = "Your API Key";
const fileName = "test.png";
const endpoint = `https://api.ayrshare.com/api/media/uploadUrl?fileName=${fileName}&contentType=png`;

const run = async () => {
  request.get(
    {
      headers: {
        "Content-Type": "application/json",
        Authorization: `Bearer ${API_KEY}`,
      },
      url: endpoint,
    },
    (err, res, body) => {
      if (err) {
        return console.error(err);
      }

      const json = JSON.parse(body);
      console.log("Upload URL:", json);

      return fs.createReadStream(`./${fileName}`).pipe(
        request.put(
          json.uploadUrl,
          {
            headers: {
              "Content-Type": json.contentType,
            },
          },
          (err, httpsResponse, body) => {
            if (err) {
              console.error("err", err);
            } else {
              console.log(body);
            }
          }
        )
      );
    }
  );
};

run();

Example Upload Binary File in Postman

You may also use Postman to upload the binary file to the uploadUrl.

In Postman:

  1. Select the HTTP Method PUT.
  2. Paste your uploadUrl in the url field. Note, the url will expire after an hour and may only be used once. If you make a call and it fails, you must regenerate the uploadUrl.
  3. In Headers set the Content-Type to be the content type returned in the /uploadUrl endpoint. For example: Content-Type: image/png.
  4. Select Body -> binary and select the file to upload.
  5. Press Send.
  6. Important: No return response will occur, so you should check if the upload was successful by opening the accessUrl returned from the /uploadUrl endpoint in a browser. You may also use the verify URL endpoint.

Postman Sample JSON File