ObjectAccessControl toObjectPb() { ObjectAccessControl objectPb = new ObjectAccessControl(); objectPb.setEntity(getEntity().toPb()); objectPb.setRole(getRole().name()); objectPb.setId(getId()); objectPb.setEtag(getEtag()); return objectPb; }
/** * Uploads data to an object in a bucket. * * @param name the name of the destination object. * @param contentType the MIME type of the data. * @param file the file to upload. * @param bucketName the name of the bucket to create the object in. */ public static void uploadFile( String name, String contentType, File file, String bucketName) throws IOException, GeneralSecurityException { InputStreamContent contentStream = new InputStreamContent( contentType, new FileInputStream(file)); // Setting the length improves upload performance contentStream.setLength(file.length()); StorageObject objectMetadata = new StorageObject() // Set the destination object name .setName(name) // Set the access control list to publicly read-only .setAcl(Arrays.asList( new ObjectAccessControl().setEntity("allUsers").setRole("READER"))); // Do the insert Storage client = StorageFactory.getService(); Storage.Objects.Insert insertRequest = client.objects().insert( bucketName, objectMetadata, contentStream); insertRequest.execute(); } // [END upload_stream]
ObjectAccessControl toObjectPb() { ObjectAccessControl objectPb = new ObjectAccessControl(); objectPb.setRole(role().name()); objectPb.setEntity(entity().toPb()); return objectPb; }
ObjectAccessControl toObjectPb() { ObjectAccessControl objectPb = new ObjectAccessControl(); objectPb.setEntity(getEntity().toPb()); objectPb.setRole(getRole().name()); objectPb.setId(getId()); objectPb.setEtag(getEtag()); return objectPb; }
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"); Insert insert = storage.objectAccessControls().insert(bucketName, objectName, publicACLItem); insert.execute(); return uploadedImage; }