InputStreamContent mediaContent = new InputStreamContent("text/plain", data); Storage.Objects.Insert insertObject = storage.objects().insert(bucketName, null, mediaContent).setName(objectName);
null, new FileContent("application/octet-stream", filePath.toFile())) .setName(filePath.getFileName().toString()) .execute(); log.info("File " + filePath.getFileName() + " created.");
insert.setName(file.getName()); insert.execute();
insert.setName(name); StorageObject obj = insert.execute(); Log.d(TAG, obj.getSelfLink());
insert.setName(file.getName()); insert.execute();
insert.setName(file.getName());
@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 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); } }
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(); }