private static void addContentMetdataFromHttpRequest( BlobBuilder.PayloadBlobBuilder builder, HttpServletRequest request) { ImmutableMap.Builder<String, String> userMetadata = ImmutableMap.builder(); for (String headerName : Collections.list(request.getHeaderNames())) { if (startsWithIgnoreCase(headerName, USER_METADATA_PREFIX)) { userMetadata.put( headerName.substring(USER_METADATA_PREFIX.length()), Strings.nullToEmpty(request.getHeader(headerName))); } } builder.cacheControl(request.getHeader( HttpHeaders.CACHE_CONTROL)) .contentDisposition(request.getHeader( HttpHeaders.CONTENT_DISPOSITION)) .contentEncoding(request.getHeader( HttpHeaders.CONTENT_ENCODING)) .contentLanguage(request.getHeader( HttpHeaders.CONTENT_LANGUAGE)) .userMetadata(userMetadata.build()); String contentType = request.getContentType(); if (contentType != null) { builder.contentType(contentType); } long expires = request.getDateHeader(HttpHeaders.EXPIRES); if (expires != -1) { builder.expires(new Date(expires)); } }
private static void addContentMetdataFromHttpRequest( BlobBuilder.PayloadBlobBuilder builder, HttpServletRequest request) { ImmutableMap.Builder<String, String> userMetadata = ImmutableMap.builder(); for (String headerName : Collections.list(request.getHeaderNames())) { if (startsWithIgnoreCase(headerName, USER_METADATA_PREFIX)) { userMetadata.put( headerName.substring(USER_METADATA_PREFIX.length()), Strings.nullToEmpty(request.getHeader(headerName))); } } builder.cacheControl(request.getHeader( HttpHeaders.CACHE_CONTROL)) .contentDisposition(request.getHeader( HttpHeaders.CONTENT_DISPOSITION)) .contentEncoding(request.getHeader( HttpHeaders.CONTENT_ENCODING)) .contentLanguage(request.getHeader( HttpHeaders.CONTENT_LANGUAGE)) .userMetadata(userMetadata.build()); String contentType = request.getContentType(); if (contentType != null) { builder.contentType(contentType); } long expires = request.getDateHeader(HttpHeaders.EXPIRES); if (expires != -1) { builder.expires(new Date(expires)); } }
private static void addContentMetdataFromHttpRequest( BlobBuilder.PayloadBlobBuilder builder, HttpServletRequest request) { ImmutableMap.Builder<String, String> userMetadata = ImmutableMap.builder(); for (String headerName : Collections.list(request.getHeaderNames())) { if (startsWithIgnoreCase(headerName, USER_METADATA_PREFIX)) { userMetadata.put( headerName.substring(USER_METADATA_PREFIX.length()), Strings.nullToEmpty(request.getHeader(headerName))); } } builder.cacheControl(request.getHeader( HttpHeaders.CACHE_CONTROL)) .contentDisposition(request.getHeader( HttpHeaders.CONTENT_DISPOSITION)) .contentEncoding(request.getHeader( HttpHeaders.CONTENT_ENCODING)) .contentLanguage(request.getHeader( HttpHeaders.CONTENT_LANGUAGE)) .userMetadata(userMetadata.build()); String contentType = request.getContentType(); if (contentType != null) { builder.contentType(contentType); } long expires = request.getDateHeader(HttpHeaders.EXPIRES); if (expires != -1) { builder.expires(new Date(expires)); } }
new HdfsPayload(new Path(hdfsUrl), conf)) .contentType(MediaType.APPLICATION_OCTET_STREAM) .contentDisposition(objectName).build(); long length = blob.getPayload().getContentMetadata().getContentLength(); blobStore.putBlob(containerName, blob, multipart());
.contentDisposition(metadata.getContentDisposition()) .contentEncoding(metadata.getContentEncoding()) .contentLanguage(metadata.getContentLanguage())
contentDisposition(blobPartName).build(); final ListenableFuture<String> futureETag = client.putObject(container, blob2Object.apply(blobPart)); futureETag.addListener(new Runnable() {
.name(key + PART_SEPARATOR + part) .payload(chunkedPart) .contentDisposition(key + PART_SEPARATOR + part).build(); client.putObject(container, blob2Object.apply(blobPart)); .name(key + PART_SEPARATOR + part) .payload(chunkedPart) .contentDisposition(key + PART_SEPARATOR + part).build(); client.putObject(container, blob2Object.apply(blobPart));
.name(key + PART_SEPARATOR + part) .payload(chunkedPart) .contentDisposition(key + PART_SEPARATOR + part).build(); client.putObject(container, blob2Object.apply(blobPart)); .name(key + PART_SEPARATOR + part) .payload(chunkedPart) .contentDisposition(key + PART_SEPARATOR + part).build(); client.putObject(container, blob2Object.apply(blobPart));
@Override public String execute(String container, Blob blob) { String key = blob.getMetadata().getName(); Payload payload = blob.getPayload(); Long length = payload.getContentMetadata().getContentLength(); checkNotNull(length, "please invoke payload.getContentMetadata().setContentLength(length) prior to multipart upload"); long chunkSize = algorithm.calculateChunkSize(length); int partCount = algorithm.getParts(); if (partCount > 0) { for (Payload part : slicer.slice(payload, chunkSize)) { int partNum = algorithm.getNextPart(); Blob blobPart = blobBuilders.get() .name(key + PART_SEPARATOR + partNum) .payload(part) .contentDisposition(key + PART_SEPARATOR + partNum) .build(); client.putObject(container, blob2Object.apply(blobPart)); } return client.putObjectManifest(container, key); } else { return client.putObject(container, blob2Object.apply(blob)); } } }
private String emulateCopyBlob(BlobStore blobStore, Response resp, BlobMetadata meta, String destContainer, String destObject, CopyOptions options) { Response.StatusType statusInfo = resp.getStatusInfo(); if (statusInfo.equals(Response.Status.OK)) { ContentMetadata contentMetadata = meta.getContentMetadata(); Map<String, String> newMetadata = new HashMap<>(); newMetadata.putAll(meta.getUserMetadata()); newMetadata.putAll(options.userMetadata()); RESERVED_METADATA.forEach(s -> newMetadata.remove(s)); Blob blob = blobStore.blobBuilder(destObject) .userMetadata(newMetadata) .payload(new InputStreamPayload((InputStream) resp.getEntity())) .contentLength(resp.getLength()) .contentDisposition(contentMetadata.getContentDisposition()) .contentEncoding(contentMetadata.getContentEncoding()) .contentType(contentMetadata.getContentType()) .contentLanguage(contentMetadata.getContentLanguage()) .build(); return blobStore.putBlob(destContainer, blob); } else { throw new ClientErrorException(statusInfo.getReasonPhrase(), statusInfo.getStatusCode()); } }
@Override public String execute(String container, Blob blob) { String key = blob.getMetadata().getName(); Payload payload = blob.getPayload(); Long length = payload.getContentMetadata().getContentLength(); checkNotNull(length, "please invoke payload.getContentMetadata().setContentLength(length) prior to multipart upload"); long chunkSize = algorithm.calculateChunkSize(length); int partCount = algorithm.getParts(); if (partCount > 0) { for (Payload part : slicer.slice(payload, chunkSize)) { int partNum = algorithm.getNextPart(); String partName = namingStrategy.getPartName(key, partNum, partCount); Blob blobPart = blobBuilders.get() .name(partName) .payload(part) .contentDisposition(partName) .build(); client.putObject(container, blob2Object.apply(blobPart)); } SwiftObject manifest = blob2Object.apply(blob); // put empty manifest object retaining existing metadata manifest.getPayload().getContentMetadata().setContentLength(0L); return client.putObjectManifest(container, manifest); } else { return client.putObject(container, blob2Object.apply(blob)); } } }
@Override public void addFile(FileEntry fileEntry, InputStream fileStream) throws FileStorageException { String entryName = fileEntry.getId(); long fileSize = fileEntry.getSize() .longValue(); Blob blob = blobStore.blobBuilder(entryName) .payload(fileStream) .contentDisposition(fileEntry.getName()) .contentType(MediaType.OCTET_STREAM.toString()) .contentLength(fileSize) .userMetadata(createFileEntryMetadata(fileEntry)) .build(); try { putBlobWithRetries(blob, 3); LOGGER.debug(MessageFormat.format(Messages.STORED_FILE_0_WITH_SIZE_1_SUCCESSFULLY_2, fileEntry.getId(), fileSize)); } catch (ContainerNotFoundException e) { throw new FileStorageException( MessageFormat.format(Messages.FILE_UPLOAD_FAILED, fileEntry.getName(), fileEntry.getNamespace())); } }
@Test(groups = "live") public void testPutBlobWithMd5() throws IOException, InterruptedException { String containerName = getContainerName(); String blobName = "md5test"; try { long contentLength = 32 * 1024L; ByteSource byteSource = TestUtils.randomByteSource().slice(0, contentLength); ByteSourcePayload payload = Payloads.newByteSourcePayload(byteSource); PayloadEnclosingImpl payloadImpl = new PayloadEnclosingImpl(payload); BlobStore blobStore = view.getBlobStore(); // This would trigger server side validation of md5 HashCode hcMd5 = byteSource.hash(Hashing.md5()); Blob blob = blobStore.blobBuilder(blobName).payload(payloadImpl.getPayload()).contentType("image/jpeg") .contentLength(contentLength).contentLanguage("en").contentDisposition("attachment") .contentMD5(hcMd5).userMetadata(ImmutableMap.of("Adrian", "powderpuff")).build(); blobStore.putBlob(containerName, blob); checkMD5(containerName, blobName, hcMd5.asBytes()); } finally { returnContainer(containerName); } } }
@Override protected void addContentMetadata(PayloadBlobBuilder blobBuilder) { blobBuilder.contentType("text/csv"); blobBuilder.contentDisposition("attachment; filename=photo.jpg"); // TODO: causes failures with subsequent GET operations: // HTTP/1.1 failed with response: HTTP/1.1 503 Service Unavailable; content: [Service Unavailable] //blobBuilder.contentEncoding("gzip"); blobBuilder.contentLanguage("en"); }
protected void addContentMetadata(PayloadBlobBuilder blobBuilder) { blobBuilder.cacheControl("max-age=3600"); blobBuilder.contentType("text/csv"); blobBuilder.contentDisposition("attachment; filename=photo.jpg"); blobBuilder.contentEncoding("gzip"); blobBuilder.contentLanguage("en"); }
private Blob createBlob( FileResource fileResource, byte[] bytes ) { return blobStore.blobBuilder( fileResource.getStorageKey() ) .payload( bytes ) .contentLength( fileResource.getContentLength() ) .contentMD5( HashCode.fromString( fileResource.getContentMd5() ) ) .contentType( fileResource.getContentType() ) .contentDisposition( "filename=" + fileResource.getName() ) .build(); }
/** * Writes {@link Payload} to the {@link BlobStore}. */ public static void writeBlob(BlobStore blobStore, String container, String blobName, Payload payload) { if (blobName != null && payload != null) { mkDirs(blobStore, container, blobName); Blob blob = blobStore.blobBuilder(blobName).payload(payload).contentType(MediaType.APPLICATION_OCTET_STREAM).contentDisposition(blobName).build(); blobStore.putBlob(container, blob, multipart()); } }
private void addContentMetadata(PayloadBlobBuilder blobBuilder) { blobBuilder.contentType("text/csv"); blobBuilder.contentDisposition("attachment; filename=photo.jpg"); blobBuilder.contentEncoding("gzip"); blobBuilder.contentLanguage("en"); }
private void uploadConstitution(String container, String name, String contentDisposition) throws IOException { view.getBlobStore().putBlob( container, view.getBlobStore().blobBuilder(name).payload(oneHundredOneConstitutions.getInput()).contentType( "text/plain").contentMD5(oneHundredOneConstitutionsMD5).contentLength( oneHundredOneConstitutionsLength).contentDisposition(contentDisposition).build()); }
private Blob createBlob( FileResource fileResource, File file ) { return blobStore.blobBuilder( fileResource.getStorageKey() ) .payload( file ) .contentLength( fileResource.getContentLength() ) .contentMD5( HashCode.fromString( fileResource.getContentMd5() ) ) .contentType( fileResource.getContentType() ) .contentDisposition( "filename=" + fileResource.getName() ) .build(); }