Skip to content

Instantly share code, notes, and snippets.

@Ikhiloya
Last active July 22, 2020 09:36
Show Gist options
  • Save Ikhiloya/e89a7aff7d595fb3896b5cfe0562077b to your computer and use it in GitHub Desktop.
Save Ikhiloya/e89a7aff7d595fb3896b5cfe0562077b to your computer and use it in GitHub Desktop.
public String[] uploadFile(MultipartFile multipartFile) throws IOException {
System.out.println("bucket name====" + bucketName);
File file = convertMultiPartToFile(multipartFile);
Path filePath = file.toPath();
String objectName = generateFileName(multipartFile);
Storage storage = storageOptions.getService();
BlobId blobId = BlobId.of(bucketName, objectName);
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).build();
Blob blob = storage.create(blobInfo, Files.readAllBytes(filePath));
log.info("File " + filePath + " uploaded to bucket " + bucketName + " as " + objectName);
return new String[]{"fileUrl", objectName};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment