com.google.api.client.util.ByteStreams Java Examples
The following examples show how to use
com.google.api.client.util.ByteStreams.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebController.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@PostMapping("/submitDocument") public ModelAndView submitDocument(@RequestParam("documentUrl") String documentUrl) throws IOException { // Uploads the document to the GCS bucket Resource documentResource = resourceLoader.getResource(documentUrl); BlobId outputBlobId = BlobId.of(ocrBucket, documentResource.getFilename()); BlobInfo blobInfo = BlobInfo.newBuilder(outputBlobId) .setContentType(getFileType(documentResource)) .build(); try (WriteChannel writer = storage.writer(blobInfo)) { ByteStreams.copy(documentResource.getInputStream(), Channels.newOutputStream(writer)); } // Run OCR on the document GoogleStorageLocation documentLocation = GoogleStorageLocation.forFile(outputBlobId.getBucket(), outputBlobId.getName()); GoogleStorageLocation outputLocation = GoogleStorageLocation.forFolder( outputBlobId.getBucket(), "ocr_results/" + documentLocation.getBlobName()); ListenableFuture<DocumentOcrResultSet> result = documentOcrTemplate.runOcrForDocument(documentLocation, outputLocation); ocrStatusReporter.registerFuture(documentLocation.uriString(), result); return new ModelAndView("submit_done"); }