Upload files with Blossom
Upload files with Blossom
Use nostr-wot-sdk/blossom to upload a user-selected file to an explicitly chosen server. The helper signs the upload authorization and returns the validated URL, hash and size. Use that URL in a separately signed profile or note.
terminal
$npm install nostr-wot-sdk@3.0.0 nostr-tools
Example
typescript
import { uploadToBlossom } from "nostr-wot-sdk/blossom";
import { Nip07Signer } from "nostr-wot-sdk/signers";
export async function upload(file: File, signal: AbortSignal) {
const blob = await uploadToBlossom(file, {
signer: new Nip07Signer(),
servers: ["https://blossom.primal.net"],
signal,
});
return { url: blob.url, hash: blob.sha256, bytes: blob.size };
}Integration notes
Public upload does not encrypt the file. For private attachments, encrypt first, then use uploadEncryptedBlob with the ciphertext. Share the decryption material only inside the encrypted message. Keep one AbortController per operation and cancel when the view or account changes; uploading a file does not publish a Nostr event.