Last active
July 22, 2020 09:36
-
-
Save Ikhiloya/e89a7aff7d595fb3896b5cfe0562077b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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