Media Snapshots
The Lens API snapshots the media content from profiles and publications on a CDN. Our goal is to provide a seamless experience to users, on par with web2, so that content delivery is quick, responsive and adjustable to your application's needs.
You will find the link and mimetype of the snapshotted media by querying the optimized
property of ImageSet
AudioSet
and VideoSet
types. If missing, it means the media is not snapshotted and you can fallback to display it using the rawURI
location.
The type of content being snapshotted is:
- Profile pictures
- Profile cover photos
- Publication media (
ImageSet
,AudioSet
,VideoSet
) and attachments (metadata.lens.attachments
)
Content not snapshotted right now:
- NFT profile pictures
- Marketplace metadata media and attributes (aka media thats not under the
metadata.lens
property)
How do I know if my content was snapshotted?
You can now subscribe to SNS notifications for media snapshots, you will get notified for both success and failure in the topics
MEDIA_SNAPSHOTTED
andMEDIA_SNAPSHOT_FAILED
. In both cases, the notifications will include theoriginalUrl
as well as the source (being a PublicationId, or a ProfileId, depending on the type of media that was snapshotted. If successful, you will also find thesnapshottedUrl
, otherwise there will be the errormessage
.
My content is not being snapshotted, why?
While most media snapshots will happen almost instantaneously, some might take some time to complete especially for typically larger types of content like audio and video, in these cases, the
optimized
field will be missing until the snapshot is complete.The current limits for snapshots are 50MB for images, 200MB for audio and 1GB for video content.
In case of failure like timeout or IPFS data not pinned yet, Lens API will retry up to 10 times. If that fails, media will not be snapshotted.
Images
Image content will be snapshotted on ImageKit as well as S3 for redundancy, and will always be served from ImageKit CDN. This applies to images up to 50MB in size, larger ones will not be snapshotted at this point. In the case of GIFs specifically, the snapshot limit is 1.2MB.
Image transformations
One common usecase is to serve image content in various sizes for different purposes. eg. A profile picture can be served as part of a post in a small format, or in the profile page in a medium format, or even in full resolution if needed. The now deprecated small
and medium
media formats were allowing this but not in a customizable way. To support these usecases, you can use the transformed
resolver on ImageSet
that will serve images in custom resolutions harnessing ImageKit's on-the-fly transformation feature.
The new field resolver takes a single input object with 3 properties width
, height
and keepAspectRatio
. width
and height
accept string values in the following forms: '500px'
for pixel-based transformations, '50%'
for transformations based on the percentage of the original image size and 'auto'
in cases you only want to supply one dimension and auto-compute the other. keepAspectRatio
is set to true by default, and you can set it as false in case you explicitly want the image to be stretched.
Here is a few GraphQL snippets using the transformed
field resolver:
... on Post {
metadata {
... on ImageMetadataV3 {
image {
image {
raw {
uri
}
optimized {
uri
}
transformed(request:{
width: "200px"
height: "10%"
keepAspectRatio:false
}) {
uri
}
}
}
}
}
... on Post {
metadata {
... on ImageMetadataV3 {
image {
image {
raw {
uri
}
optimized {
uri
}
transformed(request:{
width: "auto"
height: "100px"
}) {
uri
}
}
}
}
}
Audio
Audio content up to 200MBs in size will be snapshotted on an S3 bucket. The audio will be intact, no transcoding will be made, it will be a direct copy of the original.
Video content
Video content up to 1GB will be snapshotted on Livepeer. Snapshotting on Livepeer involves transcoding the video, so it's a lengthier process, that should take up to a few minutes.
Also, Livepeer-snapshotted videos will be served in the m3u8 format, and that might need some additional handling from your side.
Content metadata
Right now the snapshotted media will keep any metadata found in the original file (like EXIF, XMP or ID3 metadata). In case you want to omit them, please make sure you clean up the original uploaded file.
Updated 5 months ago