How to update ACL of a file in Google Cloud Storage using Java API -
i trying upload image google cloud storage , add acl of
allusers reader
java code , 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 make public objectaccesscontrol publicaclitem = new objectaccesscontrol(); publicaclitem.setentity("allusers"); publicaclitem.setrole("reader"); uploadedimage.getacl().add(publicaclitem); // how update acl ??? // , how fetch public url ?? }
i using:
<dependency> <groupid>com.google.apis</groupid> <artifactid>google-api-services-storage</artifactid> <version>v1-rev18-1.19.0</version> </dependency>
got it
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 make public objectaccesscontrol publicaclitem = new objectaccesscontrol(); publicaclitem.setentity("allusers"); publicaclitem.setrole("reader"); insert insert = storage.objectaccesscontrols().insert(bucketname, objectname, publicaclitem); insert.execute(); return uploadedimage; }
Comments
Post a Comment