Store attachments

Skip to end of metadata
Go to start of metadata

As part of a Document

You can add attachments to a Document. Saving the document will add the attachment.

String name = "java-log.png";
Document d = new Document();
InputStream is = TestClass.class.getResourceAsStream("/fixtures/image.png");
d.addAttachment(name, is);        
database.saveDocument(d);
        
Document d2 = database.fetchDocument(d.getId());
Attachment a = d2.getAttachment(name);

With an existing document:


Document d = database.fetchDocument(docId);

Attachment a = d.getAttachment("logo.png");

// Replace existing attachment
d.addAttachment("logo.png", new FileInputStream("logo2.png"));

// Add another attachment
d.addAttachment(new File("docs.tex")); // This will use the file name as the attachment name

ServerResponse response = database.saveDocument(d);

If this is an existing document and there already is an attachment with this name, the attachment will be replaced.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

Anonymous replies:

You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account. You can also Sign Up for a new account.