| | |
| | | // The path to your file to upload |
| | | // String filePath = "path/to/your/file" |
| | | String fileName = file.getOriginalFilename(); |
| | | String projectId = "i-go-gcp"; |
| | | String bucketName = "i-go"; |
| | | String projectId = "i-go-cloud"; |
| | | String bucketName = "i-go-gcs-public"; |
| | | GoogleCredentials defaultCredentials = null; |
| | | try { |
| | | defaultCredentials = GoogleCredentials.getApplicationDefault(); |
| | |
| | | storage.createFrom(blobInfo, file.getInputStream(), precondition); |
| | | System.out.println( |
| | | "File uploaded to bucket " + bucketName + " as " + fileName); |
| | | |
| | | |
| | | makeObjectPublic(projectId, bucketName, fileName); |
| | | return "https://storage.googleapis.com/i-go/" + fileName; |
| | | } catch (IOException e) { |
| | |
| | | System.out.println( |
| | | "Object " + objectName + " in bucket " + bucketName + " was made publicly readable"); |
| | | } |
| | | |
| | | |
| | | } |