I am trying to upload a image to google cloud storage and add ACL of
allUsers READER
Java code and question
public static StorageObject uploadSimpleImageAndMakeItPublic(
Storage storage, String bucketName, String objectName,
InputStream imageData) throws IOException {
InputStreamContent mediaContent = new InputStreamContent("image/png", imageData);
Storage.Objects.Insert insertObject = storage.objects().insert(bucketName, null, mediaContent).setName(objectName);
insertObject.getMediaHttpUploader().setDisableGZipContent(true);
StorageObject uploadedImage = insertObject.execute();
// new acl to make it public
ObjectAccessControl publicACLItem = new ObjectAccessControl();
publicACLItem.setEntity("allUsers");
publicACLItem.setRole("READER");
uploadedImage.getAcl().add(publicACLItem);
// HOW TO UPDATE THIS ACL NOW ???
// AND HOW TO FETCH THE PUBLIC URL ??
}
I am using:
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-storage</artifactId>
<version>v1-rev18-1.19.0</version>
</dependency>
GOT IT