Uploading InputStream in Google Storage Bucket

Viewed 879

Can I upload Input stream data in GCS ? If possible then how ? and what is mean by BlobWriteOption and BlobTargetOption in create function ?

   public void upload(String objectName,InputStream stream) throws IOException {
        Credentials credentials = GoogleCredentials.fromStream(new FileInputStream(jsonkey));

        Storage storage = StorageOptions.newBuilder().setCredentials(credentials).setProjectId(projectId).build().getService();
        BlobId blobId = BlobId.of(bucketName, objectName);
        BlobInfo blobInfo = BlobInfo.newBuilder(blobId).build();     
        
      //  storage.create(blobInfo, stream , ??);
        storage.create(blobInfo, content, options);

        log.info("File uploaded in {}",objectName);
    }

But I found this deprecated message:

The method create(BlobInfo, InputStream, Storage.BlobWriteOption...) from the type Storage is deprecated
0 Answers
Related