private static String determineName( final Blob document, final String fileName) { String name = fileName != null ? fileName : document.getName(); if(!name.toLowerCase().endsWith(".pdf")) { name = name + ".pdf"; } return name; }
private static String determineName( final Blob document, final String fileName) { String name = fileName != null ? fileName : document.getName(); if(!name.toLowerCase().endsWith(".pdf")) { name = name + ".pdf"; } return name; }
public Object getValueForDatastoreMapping(NucleusContext nucleusCtx, int index, Object value) { Blob blob = ((Blob)value); switch (index) { case 0: return blob.getName(); case 1: return blob.getMimeType().getBaseType(); case 2: return blob.getBytes(); } throw new IndexOutOfBoundsException(); }
@Override public String toString() { return getName() + " [" + getMimeType().getBaseType() + "]: " + getBytes().length + " bytes"; }
@Programmatic public void modifyBlob(Blob blob) { setName(blob.getName()); setMimeType(blob.getMimeType().toString()); setBlobBytes(blob.getBytes()); setSort(DocumentSort.BLOB); } public boolean hideBlob() {
@Programmatic public void modifyBlob(Blob blob) { setName(blob.getName()); setMimeType(blob.getMimeType().toString()); setBlobBytes(blob.getBytes()); setSort(DocumentSort.BLOB); } public boolean hideBlob() {
@Test public void when_blob_is_not_null() { final Blob val = new Blob("image.png", "image/png", new byte[]{1,2,3,4,5}); CommonDtoUtils.setValueOn(valueDto, ValueType.BLOB, val, mockBookmarkService); final BlobDto blobDto = valueDto.getBlob(); Assert.assertThat(blobDto, is(notNullValue())); Assert.assertThat(blobDto.getBytes(), is(val.getBytes())); Assert.assertThat(blobDto.getName(), is(val.getName())); Assert.assertThat(blobDto.getMimeType(), is(val.getMimeType().toString())); }
@Test public void testEncode_and_decode() { String encoded = value.toEncodedString(blob); assertEquals("myfile1.docx:application/vnd.ms-word:AQIDBA==", encoded); Blob decoded = value.fromEncodedString(encoded); assertThat(decoded.getName(), is("myfile1.docx")); assertThat(decoded.getMimeType().getPrimaryType(), is("application")); assertThat(decoded.getMimeType().getSubType(), is("vnd.ms-word")); assertThat(decoded.getBytes().length, is(4)); }
/** * @param documentName - override the name of the blob (if null, then uses the blob's name) */ @Programmatic public Document createForBlob( final DocumentType documentType, final String documentAtPath, String documentName, final Blob blob) { documentName = documentName != null? documentName: blob.getName(); final Document document = documentRepository.create( documentType, documentAtPath, documentName, blob.getMimeType().getBaseType()); document.setRenderedAt(clockService.nowAsDateTime()); document.setState(DocumentState.RENDERED); document.setSort(DocumentSort.BLOB); document.setBlobBytes(blob.getBytes()); return document; }
public void setObject(ExecutionContext ec, PreparedStatement preparedStmt, int[] exprIndex, Object value) { Blob blob = ((Blob)value); if (blob == null) { getDatastoreMapping(0).setString(preparedStmt, exprIndex[0], null); getDatastoreMapping(1).setString(preparedStmt, exprIndex[1], null); // using: // getDatastoreMapping(2).setObject(preparedStmt, exprIndex[2], null); // fails for PostgreSQL, as interprets as a reference to an oid (pointer to offline blob) // rather than a bytea (inline blob) try { preparedStmt.setBytes(exprIndex[2], null); } catch (SQLException e) { // ignore } } else { getDatastoreMapping(0).setString(preparedStmt, exprIndex[0], blob.getName()); getDatastoreMapping(1).setString(preparedStmt, exprIndex[1], blob.getMimeType().getBaseType()); getDatastoreMapping(2).setObject(preparedStmt, exprIndex[2], blob.getBytes()); } }
/** * @param documentName - override the name of the blob (if null, then uses the blob's name) */ @Programmatic public Document createForBlob( final DocumentType documentType, final String documentAtPath, String documentName, final Blob blob) { documentName = documentName != null? documentName: blob.getName(); final Document document = documentRepository.create( documentType, documentAtPath, documentName, blob.getMimeType().getBaseType()); document.setRenderedAt(clockService.nowAsDateTime()); document.setState(DocumentState.RENDERED); document.setSort(DocumentSort.BLOB); document.setBlobBytes(blob.getBytes()); return document; }
if(blob != null) { final BlobDto blobDto = new BlobDto(); blobDto.setName(blob.getName()); blobDto.setBytes(blob.getBytes()); blobDto.setMimeType(blob.getMimeType().toString());