Increasing the video and image limits in php2Bluesky

A user of my PHP2Bluesky package, Muzikals, raised an issue to say that Bluesky had increased the limits for both videos and images. Now you can upload larger-sized videos of up to 300MB and ten minutes in length, and the limit for images has been raised from four to ten.

I’d planned for this

When developing php2Bluesky I had always thought that there was a possibility that the limits would change and so, rather than hard coding them, I added the limits as constants into BlueskyConsts.php:

    // don't change these unless Bluesky changes the limits
    const MAX_IMAGE_UPLOAD_SIZE = 1000000;
    const MAX_IMAGE_UPLOAD = 4;
    const MAX_VIDEO_UPLOAD_SIZE = 50000000;
    const MAX_VIDEO_UPLOAD = 1;
    const MAX_VIDEO_DURATION = 60; // in seconds
    const MIN_POST_SIZE = 3;
    const MAX_POST_SIZE = 300;

Easy change, I thought. Just bump up the limits and off we go. So that’s what I did and set about testing the change, and immediately got this error:

Invalid app.bsky.feed.post record: array too big (maximum 4, got 5) at $.record.embed.images

That made no sense at all. I had tried to send just five images and they were being rejected. I initially thought that the change might have only been on the web interface and not the API but the truth was more complex.

Introducing Galleries

It turns our that Bluesky did increase the number of images you can post to ten, but they did not change app.bsky.embed.images from four images to ten. The Bluesky release notes state that simply increasing the old app.bsky.embed.images limit would have been a breaking lexicon change. And the current app.bsky.embed.images lexicon still says:

"images": {
  "type": "array",
  "items": { "type": "ref", "ref": "#image" },
  "maxLength": 4
}

Instead, they introduced a new embed type: app.bsky.embed.gallery which allows up to 10 photos on the same post. Interestingly, playing around I found that you can use the new gallery embed for any number of image uploads and you get a different view depending on how many you uploaded:

Number of ImagesWhat you see on post
1 imageyou get just that shown
<=4 imagesyou get the tiled block as before
>4you get the new gallery look

With that in mind I have reworked the code such that it uses the new app.bsky.embed.gallery for anything other then a sibngle image which continues to use the old method. I have also changed BlueskyConsts.php to remove the images option and replaced it with a similar gallery one:

    // don't change these unless Bluesky changes the limits
    const MAX_IMAGE_UPLOAD_SIZE = 1000000; // in bytes
    const MAX_GALLERY_IMAGES = 10;
    const MAX_VIDEO_UPLOAD_SIZE = 300000000; // in bytes
    const MAX_VIDEO_UPLOAD = 1;
    const MAX_VIDEO_DURATION = 600; // in seconds
    const MIN_POST_SIZE = 3;
    const MAX_POST_SIZE = 300; // in characters (not currently used)

The release notes from Bluesky state:

We’ll be launching with a soft limit of 10 images, and a hard limit of 20. As noted in the size limit Discussion, we want to take certain steps slowly to ensure our systems can capably scale to meet increased demand. We do not have a timeline for increasing the limit to the full 20, we’re simply doing what we can to future-proof this from the get-go.

Whenever they do increase the limit, this time the change should be straightforward. As ever you can download the code from my Github page.

Leave a Reply

Your email address will not be published. Required fields are marked *