Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

ssc-half-light/blob-store-cloudinary

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

blob store cloudinary tests

Blob storage

Use this for storage of public blobs in cloudinary.

install

npm i -S @ssc-hermes/blob-store

examples

create

import { BlobStore } from '@ssc-hermes/blob-store'

// pass in params for `cloudinary`
const store = BlobStore.Cloudinary({
    cloudName: process.env.CLOUDINARY_CLOUD_NAME as string,
    apiKey: process.env.CLOUDINARY_API_KEY as string,
    apiSecret: process.env.CLOUDINARY_API_SECRET as string
})
// or use env variables as config
const store = BlobStore.Cloudinary()  // needs `process.env.COUDINARY_*` vars

write an image

import { test } from 'tapzero'

test('write a file to cloudinary', async t => {
    // base64 encoded image
    const file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAApgAAAKYB3X3/OAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAANCSURBVEiJtZZPbBtFFMZ/M7ubXdtdb1xSFyeilBapySVU8h8OoFaooFSqiihIVIpQBKci6KEg9Q6H9kovIHoCIVQJJCKE1ENFjnAgcaSGC6rEnxBwA04Tx43t2FnvDAfjkNibxgHxnWb2e/u992bee7tCa00YFsffekFY+nUzFtjW0LrvjRXrCDIAaPLlW0nHL0SsZtVoaF98mLrx3pdhOqLtYPHChahZcYYO7KvPFxvRl5XPp1sN3adWiD1ZAqD6XYK1b/dvE5IWryTt2udLFedwc1+9kLp+vbbpoDh+6TklxBeAi9TL0taeWpdmZzQDry0AcO+jQ12RyohqqoYoo8RDwJrU+qXkjWtfi8Xxt58BdQuwQs9qC/afLwCw8tnQbqYAPsgxE1S6F3EAIXux2oQFKm0ihMsOF71dHYx+f3NND68ghCu1YIoePPQN1pGRABkJ6Bus96CutRZMydTl+TvuiRW1m3n0eDl0vRPcEysqdXn+jsQPsrHMquGeXEaY4Yk4wxWcY5V/9scqOMOVUFthatyTy8QyqwZ+kDURKoMWxNKr2EeqVKcTNOajqKoBgOE28U4tdQl5p5bwCw7BWquaZSzAPlwjlithJtp3pTImSqQRrb2Z8PHGigD4RZuNX6JYj6wj7O4TFLbCO/Mn/m8R+h6rYSUb3ekokRY6f/YukArN979jcW+V/S8g0eT/N3VN3kTqWbQ428m9/8k0P/1aIhF36PccEl6EhOcAUCrXKZXXWS3XKd2vc/TRBG9O5ELC17MmWubD2nKhUKZa26Ba2+D3P+4/MNCFwg59oWVeYhkzgN/JDR8deKBoD7Y+ljEjGZ0sosXVTvbc6RHirr2reNy1OXd6pJsQ+gqjk8VWFYmHrwBzW/n+uMPFiRwHB2I7ih8ciHFxIkd/3Omk5tCDV1t+2nNu5sxxpDFNx+huNhVT3/zMDz8usXC3ddaHBj1GHj/As08fwTS7Kt1HBTmyN29vdwAw+/wbwLVOJ3uAD1wi/dUH7Qei66PfyuRj4Ik9is+hglfbkbfR3cnZm7chlUWLdwmprtCohX4HUtlOcQjLYCu+fzGJH2QRKvP3UNz8bWk1qMxjGTOMThZ3kvgLI5AzFfo379UAAAAASUVORK5CYII='

    hash = (await store.write(file)).hash
    t.equal(typeof hash, 'string', 'hash was returned')
    t.equal(hash, 'GmuzSvBeEBT5tvt1vhtRkhl1a7V8MkTqCxT4Z4jFz_s',
        'should return the expected hash')
})

get a URL

import { test } from 'tapzero'
import { read } from '@ssc-hermes/blob-store/read'
import { scale } from '@cloudinary/url-gen/actions/resize'

test('read the file we just wrote', async t => {
    const cld = read({ cloudName: 'nichoth' })
    const url = (cld
        .image(hash)
        .resize(scale().width(100))
        .toURL())

    t.ok(url.includes('https'), 'should return an https URL')
    t.ok(url.includes(hash), 'url should include the filename')
})

About

Store blobs by content address

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published