@os-team/yandex-image-storage
v1.2.2
Published
Library for uploading images to the Yandex Cloud Storage.
Readme
@os-team/yandex-image-storage

Library for uploading images to the Yandex Cloud Storage.
Usually when you want to store an image you need:
- Validate the file type (e.g. allow only JPG, PNG, WEBP image formats). The file type should be detected by the first bytes, not by the file name (e.g. using the file-type library).
- Validate the file size.
- Convert the image to a specific extension (e.g. to JPG).
- Upload an image in multiple sizes to use them on the frontend side in different places (e.g. a large avatar on the profile page, a small avatar in the header).
- Crop some sizes of the image to use them, for example, in a list of blog posts.
- Append a hash to the file name to avoid caching when updating the image.
- Delete old images that have been replaced with new ones.
This library performs all these steps.
Usage
Install the package using the following command:
yarn add @os-team/yandex-image-storage @os-team/yc-storageExample
import YandexStorage from '@os-team/yc-storage';
import YandexImageStorage from '@os-team/yandex-image-storage';
// Initialize the Yandex Cloud Storage
const storage = new YandexStorage({
accessKeyId: 'accessKeyId',
secretAccessKey: 'secretAccessKey',
region: 'ru-central1-a',
});
// Initialize the Image Storage
const imageStorage = new YandexImageStorage({
storage,
bucket: 'my-bucket',
});
// Upload an image
const { name } = await imageStorage.upload({
body: createReadStream('my-image.jpg'),
name: 'name',
});
// Delete the image
await imageStorage.delete(name);This library extends the @os-team/image-storage lib, so see it for more information about uploading and deleting files.
