Last active
July 22, 2020 09:37
-
-
Save Ikhiloya/f817dda14d39924569083bc419c743d7 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 { | |
| 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