abashev / vfs-s3

Amazon S3 driver for Apache commons-vfs (Virtual File System) project
Apache License 2.0
92 stars 50 forks source link

Setting permissions of uploaded pictures #35

Closed ptahchiev closed 8 years ago

ptahchiev commented 8 years ago

This could be a question, or a bug - I don't really know. I am able to upload pictures to S3, and I also try to set read permissions with this:

file.setReadable(true, false);

According to the javadoc of VFS this method will Sets the owner's (or everybody's) read permission.. However my pictures are uploaded, but only with owner read permissions. I have to manually select Add more permissions -> Grantee: everyone -> Open/download from the s3 console.

How can I set permissions of the uploaded file? Is this even implemented?

ptahchiev commented 8 years ago

screenshot

ptahchiev commented 8 years ago

Closing this issue, I was actually able to do it with the following code:

        IAclGetter aclGetter = (IAclGetter) file.getFileOperations().getOperation(IAclGetter.class);
        aclGetter.process();
        Acl fileAcl = aclGetter.getAcl();

        IAclSetter aclSetter = (IAclSetter) file.getFileOperations().getOperation(IAclSetter.class);

        fileAcl.allow(Acl.Group.EVERYONE, Acl.Permission.READ);

        aclSetter.setAcl(fileAcl);
        aclSetter.process();