Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- val storage: Storage = StorageOptions.getDefaultInstance.getService
- val fileContent = Files.readAllBytes(file.toPath)
- val fileId: BlobId = BlobId.of(bucketName, s"$folderName/$fileName")
- val fileInfo: BlobInfo = BlobInfo.newBuilder(fileId).build()
- storage.create(fileInfo, fileContent)
- val storage: Storage = StorageOptions.getDefaultInstance.getService
- val outputPath = s"$folderName/$fileName"
- val fileInfo: BlobInfo = BlobInfo.newBuilder(bucketName, outputPath).build()
- val optionWrite: SignUrlOption = Storage.SignUrlOption.httpMethod(HttpMethod.PUT)
- val signedUrl: URL = storage.signUrl(fileInfo, 30, TimeUnit.MINUTES, optionWrite)
- val connection = signedUrl.openConnection
- connection.setDoOutput(true)
- val out = connection.getOutputStream
- val inputStream = Files.newInputStream(file.toPath)
- var nextByte = inputStream.read()
- while (nextByte != -1) {
- out.write(nextByte)
- nextByte = inputStream.read()
- }
- out.flush()
- inputStream.close()
- out.close()
- "com.google.cloud" % "google-cloud-storage" % "1.12.0"
Add Comment
Please, Sign In to add comment