var blob = new Blob([byteArray], {type: contentType});
@Override public String toString() { return getName() + " [" + getMimeType().getBaseType() + "]: " + getBytes().length + " bytes"; }
@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())); }
@Action( semantics = SemanticsOf.IDEMPOTENT, domainEvent = ActionDomainEvent.class ) @ActionLayout(contributed = Contributed.AS_ACTION) public DocumentTemplate $$( @ParameterLayout(named = "File") final Blob blob ) { documentTemplate.setMimeType(blob.getMimeType().toString()); documentTemplate.setBlobBytes(blob.getBytes()); return documentTemplate; }
@Override public byte[] asBytes(final DocumentAbstract<?> document) { final FactoryService factoryService = document.factoryService; final Blob blob = factoryService.mixin(Document_downloadExternalUrlAsBlob.class, document).$$(); return blob.getBytes(); } },
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 Blob(String name, String primaryType, String subtype, byte[] bytes) { this(name, newMimeType(primaryType, subtype), bytes); }
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(); }
@Action( semantics = SemanticsOf.IDEMPOTENT, domainEvent = ActionDomainEvent.class ) @ActionLayout(contributed = Contributed.AS_ACTION) public DocumentTemplate $$( @ParameterLayout(named = "File") final Blob blob ) { documentTemplate.setMimeType(blob.getMimeType().toString()); documentTemplate.setBlobBytes(blob.getBytes()); return documentTemplate; }
@Override public byte[] asBytes(final DocumentAbstract<?> document) { final FactoryService factoryService = document.factoryService; final Blob blob = factoryService.mixin(Document_downloadExternalUrlAsBlob.class, document).$$(); return blob.getBytes(); } },
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 Blob(String name, String mimeTypeBase, byte[] bytes) { this(name, newMimeType(mimeTypeBase), bytes); }
var textFile = null, makeTextFile = function (text) { var data = new Blob([text], {type: 'text/plain'}); // If we are replacing a previously generated file we need to // manually revoke the object URL to avoid memory leaks. if (textFile !== null) { window.URL.revokeObjectURL(textFile); } textFile = window.URL.createObjectURL(data); // returns a URL you can use as a href return textFile; };
@Programmatic public void modifyBlob(Blob blob) { setName(blob.getName()); setMimeType(blob.getMimeType().toString()); setBlobBytes(blob.getBytes()); setSort(DocumentSort.BLOB); } public boolean hideBlob() {
@Action( semantics = SemanticsOf.NON_IDEMPOTENT, domainEvent = ActionDomainEvent.class ) @ActionLayout( contributed = Contributed.AS_ACTION, cssClassFa = "paperclip", named = "Attach supporting PDF" ) public Document exec( final DocumentType documentType, @Parameter(fileAccept = "application/pdf") final Blob document, @Parameter(optionality = Optionality.OPTIONAL) @ParameterLayout(named = "File name") final String fileName, @Parameter(optionality = Optionality.OPTIONAL) @ParameterLayout(named = "Role name") final String roleName ) throws IOException { String name = determineName(document, fileName); final Document doc = documentRepository.create( documentType, this.document.getAtPath(), name, document.getMimeType().getBaseType()); // unlike documents that are generated from a template (where we call documentTemplate#render), in this case // we have the actual bytes; so we just set up the remaining state of the document manually. doc.setRenderedAt(clockService.nowAsDateTime()); doc.setState(DocumentState.RENDERED); doc.setSort(DocumentSort.BLOB); doc.setBlobBytes(document.getBytes()); paperclipRepository.attach(doc, roleName, this.document); return this.document; }
var blob = new Blob(["some text"], { type: "text/plain;charset=utf-8;", }); saveAs(blob, "thing.txt");
@Programmatic public void modifyBlob(Blob blob) { setName(blob.getName()); setMimeType(blob.getMimeType().toString()); setBlobBytes(blob.getBytes()); setSort(DocumentSort.BLOB); } public boolean hideBlob() {
@Action( semantics = SemanticsOf.NON_IDEMPOTENT, domainEvent = ActionDomainEvent.class ) @ActionLayout( contributed = Contributed.AS_ACTION, cssClassFa = "paperclip", named = "Attach supporting PDF" ) public Document exec( final DocumentType documentType, @Parameter(fileAccept = "application/pdf") final Blob document, @Parameter(optionality = Optionality.OPTIONAL) @ParameterLayout(named = "File name") final String fileName, @Parameter(optionality = Optionality.OPTIONAL) @ParameterLayout(named = "Role name") final String roleName ) throws IOException { String name = determineName(document, fileName); final Document doc = documentRepository.create( documentType, this.document.getAtPath(), name, document.getMimeType().getBaseType()); // unlike documents that are generated from a template (where we call documentTemplate#render), in this case // we have the actual bytes; so we just set up the remaining state of the document manually. doc.setRenderedAt(clockService.nowAsDateTime()); doc.setState(DocumentState.RENDERED); doc.setSort(DocumentSort.BLOB); doc.setBlobBytes(document.getBytes()); paperclipRepository.attach(doc, roleName, this.document); return this.document; }
var data = {a:1, b:2, c:3}; var json = JSON.stringify(data); var blob = new Blob([json], {type: "application/json"}); var url = URL.createObjectURL(blob); var a = document.createElement('a'); a.download = "backup.json"; a.href = url; a.textContent = "Download backup.json";
/** * @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; }