Blossom Uploader ​
Blossom is a new protocol that challenges IPFS with the simplicity of Nostr.
Files are uploaded to multiple servers and identified by their SHA-256 hash. If a server goes offline, clients may be able to locate the file on other servers.
Usage ​
The BlossomUploader can be used to upload files to multiple Blossom servers at once.
ts
import { BlossomUploader } from '@nostrify/nostrify/uploaders';
const uploader = new BlossomUploader({
servers: ['https://blossom.primal.net/' /*, https://cdn.satellite.earth */],
signer: window.nostr,
});
const tags = await uploader.upload(file);Options ​
serversarray of URLs to Blossom servers.signerNostr signer instance to sign the upload request.fetch(optional) custom fetch implementation.expiresIn(optional) number of milliseconds each upload request should expire in. (Default:60_000)
Uploading from the filesystem ​
The upload method accepts a File object. To upload a local file in Node.js or Deno, read it into a File first:
ts
// Node.js
import { readFile } from 'node:fs/promises';
const data = await readFile('./cat.png');
const file = new File([data], 'cat.png', { type: 'image/png' });
// Deno
const data = await Deno.readFile('./cat.png');
const file = new File([data], 'cat.png', { type: 'image/png' });Then pass it to the uploader:
ts
const tags = await uploader.upload(file);Results ​
Results are returned as a tags array (string[][]) of NIP-94 tags. The first tag is guaranteed to be a url.
ts
[
['url', 'https://blossom.primal.net/7508bd9d8b0ed6e0891a3b973adf6011b1e49f6174910d6a1eb722a4a2e30539.png'],
['x', '7508bd9d8b0ed6e0891a3b973adf6011b1e49f6174910d6a1eb722a4a2e30539'],
['ox', '7508bd9d8b0ed6e0891a3b973adf6011b1e49f6174910d6a1eb722a4a2e30539'],
['size', '172'],
['m', 'image/png'],
];urlpublic URL of the file.xSHA-256 hex-encoded string of the file.oxSHA-256 hex-encoded string of the original file, before any transformations done by the upload server.sizesize of file in bytes.mstring indicating the data type of the file. The MIME types format must be used, and they should be lowercase.