storageObject, new InputStreamContent(storageObject.getContentType(), content)); insert.getMediaHttpUploader().setDirectUploadEnabled(true); Boolean disableGzipContent = Option.IF_DISABLE_GZIP_CONTENT.getBoolean(options); if (disableGzipContent != null) {
insertObject.getMediaHttpUploader().setDisableGZipContent(true);
@Override public void store(BuildCacheKey buildCacheKey, BuildCacheEntryWriter buildCacheEntryWriter) throws BuildCacheException { final String bucketPath = getBucketPath(buildCacheKey); logger.info("Start storing cache entry '{}' in GCS bucket", bucketPath); try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { buildCacheEntryWriter.writeTo(os); try (InputStream is = new ByteArrayInputStream(os.toByteArray())) { InputStreamContent content = new InputStreamContent(BUILD_CACHE_CONTENT_TYPE, is); StorageObject metadataObject = new StorageObject().setMetadata(new HashMap<>()); Storage.Objects.Insert insertObject = storage.objects().insert(bucketName, metadataObject, content).setName(bucketPath); insertObject.getMediaHttpUploader().setDisableGZipContent(true); insertObject.execute(); } } catch (IOException e) { throw new BuildCacheException("Error while storing cache object in GCS bucket", e); } }
storageObject, new InputStreamContent(storageObject.getContentType(), content)); insert.getMediaHttpUploader().setDirectUploadEnabled(true); Boolean disableGzipContent = Option.IF_DISABLE_GZIP_CONTENT.getBoolean(options); if (disableGzipContent != null) {
@Override public Insert createRequest(InputStreamContent inputStream) throws IOException { // Create object with the given name and metadata. StorageObject object = new StorageObject() .setMetadata(metadata) .setName(objectName); Insert insert = gcs.objects().insert(bucketName, object, inputStream); writeConditions.apply(insert); if (insert.getMediaHttpUploader() != null) { insert.getMediaHttpUploader().setDirectUploadEnabled(isDirectUploadEnabled()); insert.getMediaHttpUploader().setProgressListener( new LoggingMediaHttpUploaderProgressListener(this.objectName, MIN_LOGGING_INTERVAL_MS)); } insert.setName(objectName); if (kmsKeyName != null) { insert.setKmsKeyName(kmsKeyName); } return insert; }
@Override public StorageObject create(StorageObject storageObject, final InputStream content, Map<Option, ?> options) { try { Storage.Objects.Insert insert = storage.objects() .insert(storageObject.getBucket(), storageObject, new InputStreamContent(storageObject.getContentType(), content)); insert.getMediaHttpUploader().setDirectUploadEnabled(true); return insert.setProjection(DEFAULT_PROJECTION) .setPredefinedAcl(PREDEFINED_ACL.getString(options)) .setIfMetagenerationMatch(IF_METAGENERATION_MATCH.getLong(options)) .setIfMetagenerationNotMatch(IF_METAGENERATION_NOT_MATCH.getLong(options)) .setIfGenerationMatch(IF_GENERATION_MATCH.getLong(options)) .setIfGenerationNotMatch(IF_GENERATION_NOT_MATCH.getLong(options)) .execute(); } catch (IOException ex) { throw translate(ex); } }
public static StorageObject uploadSimpleImageAndMakeItPublic( Storage storage, String bucketName, String objectName, InputStream imageData) throws IOException { InputStreamContent mediaContent = new InputStreamContent("image/png", imageData); Storage.Objects.Insert insertObject = storage.objects() .insert(bucketName, null, mediaContent).setName(objectName); insertObject.getMediaHttpUploader().setDisableGZipContent(true); StorageObject uploadedImage = insertObject.execute(); // new acl to make it public ObjectAccessControl publicACLItem = new ObjectAccessControl(); publicACLItem.setEntity("allUsers"); publicACLItem.setRole("READER"); Insert insert = storage.objectAccessControls().insert(bucketName, objectName, publicACLItem); insert.execute(); return uploadedImage; }
Storage.Objects.Insert insert = storage.objects().insert(bucket.getName(), so, content); insert.getMediaHttpUploader().setDirectUploadEnabled(true); insert.execute();
public static StorageObject uploadWithMetadata(Storage storage, StorageObject object, InputStream data) throws IOException { InputStreamContent mediaContent = new InputStreamContent(object.getContentType(), data); Storage.Objects.Insert insertObject = storage.objects().insert(object.getBucket(), object, mediaContent); insertObject.getMediaHttpUploader().setDisableGZipContent(true); return insertObject.execute(); }
public static StorageObject uploadSimple(Storage storage, String bucketName, String objectName, InputStream data, String contentType) throws IOException { InputStreamContent mediaContent = new InputStreamContent(contentType, data); Storage.Objects.Insert insertObject = storage.objects().insert(bucketName, null, mediaContent) .setName(objectName); // The media uploader gzips content by default, and alters the Content-Encoding accordingly. // GCS dutifully stores content as-uploaded. This line disables the media uploader behavior, // so the service stores exactly what is in the InputStream, without transformation. insertObject.getMediaHttpUploader().setDisableGZipContent(true); return insertObject.execute(); }
public void insert(final String bucket, final String path, AbstractInputStreamContent mediaContent) throws IOException { Storage.Objects.Insert insertObject = storage.objects().insert(bucket, null, mediaContent); insertObject.setName(path); insertObject.getMediaHttpUploader().setDirectUploadEnabled(false); insertObject.execute(); }