Guest User

Untitled

a guest
Dec 18th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. val storage: Storage = StorageOptions.getDefaultInstance.getService
  2. val fileContent = Files.readAllBytes(file.toPath)
  3. val fileId: BlobId = BlobId.of(bucketName, s"$folderName/$fileName")
  4. val fileInfo: BlobInfo = BlobInfo.newBuilder(fileId).build()
  5. storage.create(fileInfo, fileContent)
  6.  
  7. val storage: Storage = StorageOptions.getDefaultInstance.getService
  8. val outputPath = s"$folderName/$fileName"
  9. val fileInfo: BlobInfo = BlobInfo.newBuilder(bucketName, outputPath).build()
  10. val optionWrite: SignUrlOption = Storage.SignUrlOption.httpMethod(HttpMethod.PUT)
  11. val signedUrl: URL = storage.signUrl(fileInfo, 30, TimeUnit.MINUTES, optionWrite)
  12. val connection = signedUrl.openConnection
  13. connection.setDoOutput(true)
  14. val out = connection.getOutputStream
  15.  
  16. val inputStream = Files.newInputStream(file.toPath)
  17. var nextByte = inputStream.read()
  18. while (nextByte != -1) {
  19. out.write(nextByte)
  20. nextByte = inputStream.read()
  21. }
  22. out.flush()
  23. inputStream.close()
  24. out.close()
  25.  
  26. "com.google.cloud" % "google-cloud-storage" % "1.12.0"
Add Comment
Please, Sign In to add comment