Class StorageImageFile
An object-oriented representation of an image file in storage.
Example Usage
import {StorageImageFile} from '@app/storage'
import {jsx} from '@app/html-jsx'
app.html('/', () => {
const hash = 'image_aB3kHmKgLn.7301x4873.jpeg'
const file = new StorageImageFile(hash)
return <html><body>
<p>File {file.hash}</p>
<p>Type: {file.type}</p>
<p>
Width and height parameters are set:
<img src={file.getThumbnailUrl(100, 100)} />
</p>
<p>
Width parameter is set, height is omitted:
<img src={file.getThumbnailUrl(100, undefined)} />
</p>
<p>
Height parameter is set, width is omitted:
<img src={file.getThumbnailUrl(undefined, 100)} />
</p>
<p><a href={file.downloadUrl}>Download</a></p>
</body></html>
})
Properties:
- hash - The hash of the file.
- type - The type of the file. Can be: file, image, video, audio.
- downloadUrl - URL for downloading the file. The file will be served with an HTTP header forcing the download instead of opening it in the browser window. There is no need to open the file in a new tab.
- getThumbnailUrl - URL of the image file scaled to the specified parameters. Accepts width and height parameters. Both parameters can be passed, or just one. If both parameters are provided, the image will be resized on the server side according to the principle of object-fit: contain. If only one parameter is provided, the other will be calculated automatically while maintaining the aspect ratio of the image. Parameters:
- width - Width of the image in pixels.
- height - Height of the image in pixels.
- getThumbnailSrc - Used to form the src parameter of the <img> block in AppUi.
- width - Width of the original video. Throws an exception if unknown.
- widthMaybe - Width of the original video. Returns undefined if unknown.
- height - Height of the original video. Throws an exception if unknown.
- heightMaybe - Height of the original video. Returns undefined if unknown.
- sizes - Size of the original video { width: number, height: number }. Throws an exception if unknown.
- sizesMaybe - Size of the original video { width: number, height: number }. Returns undefined if unknown.