media

Media API Endpoint: Upload and manage your images and videos. Premium or Business Plan required.

Media API Endpoint

Manage your image and video gallery by uploading and retrieving images and videos. Please be sure to verify the media URL before using it to post.

Recommendation: If you already have your media accessible by an external URL, such as an S3 bucket, you can skip uploading the files to Ayrshare. Just POST to the /post endpoint with your externally accessible URL in the mediaURLs body parameter and your file will automatically be uploaded.

Click the in the endpoint to view details.

Upload Image or Video

POST https://app.ayrshare.com/api/media/upload

This endpoint allows you to upload a file or an image or small video to include in your post. Returned will be the URL to the image that can be used in the /post endpoint. Your can pass the file either as a multipart form data as a form parameter or a Base64 encoded file as a body parameter. Note 1: Media is available for 90 days after upload. All sent posts are unaffected. Note 2: Max size is 10 MB. See uploadUrl API endpoint below for larger files. Premium or Business Plan required.

Headers

NameTypeDescription

Authorizaton*

string

Format: Authorization: Bearer API_KEY. See Overview for more information.

Content-Type*

string

multipart/form-data if sending a multipart form data - see below. Otherwise, send the standard application/json.

Request Body

NameTypeDescription

file*

string or object

Send as Base64

Send the media file as a Base64 encoded string as a Data URI string. The string should begin with data:content/type;base64 Example encoding with Output Format Data URI: Image: https://base64.guru/converter/encode/image Video: https://base64.guru/converter/encode/video Note: The /post endpoint accepts larger files via an external URL with the mediaUrls parameter.

Send as Multipart Form-Data

Send the media file as a multipart form-data object. Please be sure to specify the Content-Type as mentioned above.

fileName

string

The name of the file for later reference.

description

string

A description for later reference.

{
    "id": "1167335b-6c37-4fc6-ab8a-044e0005d335-jpeg",
    "url": "https://images.ayrshare.com/q3Ls85VTsrbODnGIJHpy7PaHWwA3/1167335b-6c37-4fc6-ab8a-044ed885d.jpeg",
    "url_1080": "https://images.ayrshare.com/q3Ls85VTsrbODnGIJHpy7PaHWwA3/1167335b-6c37-4fc6-ab8a-044ed885d_1080x1080.jpeg",
    "fileName": "fun.jpg",
    "description": "good times"
}

Request Examples

curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"file": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ...", "fileName": "test.png", "description": "best image"}' \
-X POST https://app.ayrshare.com/api/media/upload

Upload Large Media Files

GET https://app.ayrshare.com/api/media/uploadUrl

For file uploads greater than 10 MB, obtain a presigned URL to upload a file. Note: - 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 sent posts are unaffected. Premium or Business Plan required.

Query Parameters

NameTypeDescription

fileName*

string

If the contentType is not present, 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.

Headers

NameTypeDescription

Authorization*

string

Format: Authorization: Bearer API_KEY. See Overview for more information.

{
    "accessUrl": "https://img.ayr.app/Aswmfs3dIEbwLSdhTwnTPJq5UlV2/test.mp4",
    "contentType": "video/mp4",
    "uploadUrl": "https://storage.googleapis.com/..."
}

Request Examples

curl \
-H "Authorization: Bearer [API Key]" \
-X GET https://app.ayrshare.com/api/media/uploadUrl?fileName=test.mov&contentType=mov
  • 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.

curl -X PUT \
-H 'Content-Type: video/mp4' \
--upload-file LOCAL_FILE_PATH uploadUrl

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://app.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.


Verify Media URL Exists

POST https://app.ayrshare.com/api/media/urlExists

Verify that the media file exists when uploaded. It should be used in conjunction with the /media/uploadUrl endpoint.

Headers

NameTypeDescription

Authorization*

string

Format: Authorization: Bearer API_KEY. See Overview for more information.

Request Body

NameTypeDescription

mediaUrl*

string

URL of the media to verify exists.

{
    "status": "success"
}

Request Examples

curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"mediaUrl": "https://img.ayrshare.com/012/vid.mp4"}' \
-X POST https://app.ayrshare.com/api/media/urlExists

GET https://app.ayrshare.com/api/media

Retrieve all the images uploaded to the image gallery include resized images ideal for Instagram.

Headers

NameTypeDescription

Authorization*

string

Format: Authorization: Bearer API_Key See Overview for more information.

[
    {
        "id": "5553a26a-cffb-4a31-bd89-dee296d35648-jpeg",
        "timeCreated": "2020-07-30T20:23:49.774Z",
        "size": "223340",
        "url": "https://images.ayrshare.com/LW8kx9Q5smXeJl5CujF7DxFAF1q1/5553a26a-cffb-4a31-bd89-dee296d35648.jpeg",
        "url_1080": "https://images.ayrshare.com/LW8kx9Q5smXeJl5CujF7DxFAF1q1/5553a26a-cffb-4a31-bd89-dee296d35648_1080x1080.jpeg",
        "fileName": "test1.jpeg",
        "description": "Test1"
    },
    {
        "id": "93383cc7-7a15-4d16-a5fa-fdda1f9bebe2-jpeg",
        "timeCreated": "2020-07-30T20:24:57.421Z",
        "size": "223340",
        "url": "https://images.ayrshare.com/LW8kx9Q5smXeJl5CujF7DxFAF1q1/93383cc7-7a15-4d16-a5fa-fdda1f9bebe2.jpeg",
        "url_1080": "https://images.ayrshare.com/LW8kx9Q5smXeJl5CujF7DxFAF1q1/93383cc7-7a15-4d16-a5fa-fdda1f9bebe2_1080x1080.jpeg",
        "fileName": "test2.jpeg",
        "description": "Test2"
    }
]

Request Examples

curl \
-H "Authorization: Bearer [API Key]" \
-X GET https://app.ayrshare.com/api/media

Resize an image

POST https://app.ayrshare.com/api/media/resize

The social networks have specific requirements for social media images. The resize endpoint allows you to choose a social network compatible image size, add watermarks, change backgrounds, and more.

Headers

NameTypeDescription

Authorization*

string

Authorization: Bearer API_KEY See Overview for more information.

Request Body

NameTypeDescription

imageUrl*

string

URL of image to be resized. Must begin with https://

file

object

Send the media file as a multipart form-data object. Required if imageUrl not present.

watermarkUrl

string

URL of watermark to be applied to resized image. The watermark will appear in the lower right corner of the image. Please see below for details.

platform*

string

Social media platform for which the URL will be resized. Please see below for details.

effects

object

Change opacity, colors, etc. Please see below for details.

dimensions

object

Object specifying width and height for resizing. E.g:

{ “width”: 500, “height”: 500 }

Required if platform is not specified.

mode

string

Value: "blur". Please see below for details.

{
    "status": "success",
    "url": "https://media.ayrshare.com/9abf1426d6ce9122ef11c72bd62e59807c5cc083/8UbyBjHTxgHkAC1I37e6O.jpg",
    "platform": "instagram",
    "mode": "blur",
    "effects": {
        "color": "#A020F0"
    }
}

Request Examples

curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"mediaUrl": "https://img.ayrshare.com/012/gb.jpg", "platform": "instagram"' \
-X POST https://app.ayrshare.com/api/media/resize

Platform Options

Specify a platform as a String to use predefined dimensions of the image. If may specify your own with dimension field.

For example "platform": "facebook" will set the dimension of the image as width 1200 px and height 630px.

  • facebook: 1200px width, 630px height.

  • instagram: 1080px width, 1080px height.

  • instagram_landscape: 1080px width, 680px height.

  • instagram_portrait: 1080px width, 1350px height.

  • instagram_special: 1080px width, 800px height.

  • linkedin: 1200px width, 627px height.

  • pinterest: 1080px width, 1920px height.

  • twitter: 1600px width, 900px height.

Mode

Blur

Blur effect will duplicate the image as a background and blur.

For example:

{
    "mediaUrl": "https://img.ayrshare.com/012/gb.jpg",
    "platform": "instagram",
    "mode": "blur"
}

Results in the image:

Watermark

You may add a watermark to the image by providing a URL, which must begin with https://. The watermark will appear in the bottom right corner of the image. We recommend a PNG with a transparent background.

For example:

{
    "mediaUrl": "https://img.ayrshare.com/012/gb.jpg",
    "platform": "facebook",
    "watermarkUrl": "https://img.ayrshare.com/012/100-percent.png"
}

Result in the image:

Effects Options

Color Hexadecimal

Hexadecimal value for color of background for blur. Only applicable if "mode": "blur". String value, e.g. "#A020F0"

For example:

{
    "mediaUrl": "https://img.ayrshare.com/012/gb.jpg",
    "platform": "instagram",
    "mode": "blur",
    "effects": {
        "color": "#A020F0"
    }
}

Result in the image:

Color: Grayscale, Sepia, Invert

You made change the primary image color by specifying grayscale, sepia, or invert. The field "blur": true is not required and should not be used if you do not want a background.

For example:

{
    "mediaUrl": "https://img.ayrshare.com/012/gb.jpg",
    "platform": "instagram",
    "effects": {
        "color": "grayscale"
    }
}

Result in the image:

Opacity

Set the opacity of the image. Number value range: 0 - 1. For example: "opacity": 0.2

Quality

For JPG or JEPG images specify the quality, or amount of compression, of the image. The lower the number the more compressed, but lower the image quality. The higher the number the less compressed, but the higher the image quality. Number value range: 0 - 100. For example: "quality": 20


Metadata on a media file

GET https://app.ayrshare.com/api/media/meta

Get the metadata on a provided media file URL.

Query Parameters

NameTypeDescription

url*

string

Encoded URI of the externally accessible media file URL.

Headers

NameTypeDescription

Authorization*

string

Format: Authorization: Bearer API_KEY. See Overview for more information.

{
    "codec": "h264",
    "duration": 28.24, // In seconds
    "filename": "https://img.ayrshare.com/random/landscape16.mp4",
    "format": "QuickTime / MOV",
    "height": 1080,
    "size": 16275959, // In bytes
    "type": "video",
    "width": 1920
}

Request Examples

GET https://app.ayrshare.com/api/media/meta?url=https%3A%2F%2Fimg.ayrshare.com%2Frandom%2Flandscape16.mp4

Last updated