Attachments: Storing Attachments

In order to store an attachment in RavenDB you need to create a document. Then you can attach an attachment to the document using the method.

Attachments, just like documents, are a part of the session and will be only saved on the Server when DocumentSession.saveChanges() is executed (you can read more about saving changes in session here).


Attachments can be stored using one of the following methods:, name, stream, [contentType]);, name, stream, [contentType]);
entity or documentId object or string instance of the entity or the entity ID
name string attachment name
stream Readable or Buffer attachment content
contentType string attachment content type


const session = store.openSession();

const file1 = fs.createReadStream("001.jpg");
const file2 = fs.createReadStream("002.jpg");
const file3 = fs.createReadStream("003.jpg");
const file4 = fs.createReadStream("004.mp4");

const album = new Album(); = "Holidays";
album.description = "Holidays travel pictures of the all family";
album.tags = [ "Holidays Travel", "All Family" ];
await, "albums/1");

    .store("albums/1", "001.jpg", file1, "image/jpeg");
    .store("albums/1", "002.jpg", file2, "image/jpeg");
    .store("albums/1", "003.jpg", file3, "image/jpeg");
    .store("albums/1", "004.mp4", file4, "video/mp4");

await session.saveChanges();