Search in sources :

Example 1 with PhotoUpload

use of cloudinary.models.PhotoUpload in project cloudinary_java by cloudinary.

the class PhotoController method listPhotos.

@RequestMapping(value = "/", method = RequestMethod.GET)
public String listPhotos(ModelMap model) {
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    Key photoKey = KeyFactory.createKey("photos", "album");
    List<Entity> photoEntities = datastore.prepare(new Query("photo", photoKey)).asList(FetchOptions.Builder.withDefaults());
    List<PhotoUpload> photos = new java.util.ArrayList<PhotoUpload>();
    for (int i = 0, n = photoEntities.size(); i < n; i++) {
        photos.add(new PhotoUpload(photoEntities.get(i)));
    }
    model.addAttribute("photos", photos);
    return "photos";
}
Also used : Entity(com.google.appengine.api.datastore.Entity) Query(com.google.appengine.api.datastore.Query) DatastoreService(com.google.appengine.api.datastore.DatastoreService) PhotoUpload(cloudinary.models.PhotoUpload) Key(com.google.appengine.api.datastore.Key)

Example 2 with PhotoUpload

use of cloudinary.models.PhotoUpload in project cloudinary_java by cloudinary.

the class PhotoController method directUploadPhotoForm.

@RequestMapping(value = "/direct_upload_form", method = RequestMethod.GET)
public String directUploadPhotoForm(ModelMap model) {
    model.addAttribute("photoUpload", new PhotoUpload());
    model.addAttribute("unsigned", false);
    return "direct_upload_form";
}
Also used : PhotoUpload(cloudinary.models.PhotoUpload)

Example 3 with PhotoUpload

use of cloudinary.models.PhotoUpload in project cloudinary_java by cloudinary.

the class PhotoController method directUnsignedUploadPhotoForm.

@SuppressWarnings("unchecked")
@RequestMapping(value = "/direct_unsigned_upload_form", method = RequestMethod.GET)
public String directUnsignedUploadPhotoForm(ModelMap model) throws Exception {
    model.addAttribute("photoUpload", new PhotoUpload());
    model.addAttribute("unsigned", true);
    Cloudinary cld = Singleton.getCloudinary();
    String preset = "sample_" + cld.apiSignRequest(ObjectUtils.asMap("api_key", cld.config.apiKey), cld.config.apiSecret).substring(0, 10);
    model.addAttribute("preset", preset);
    try {
        Singleton.getCloudinary().api().createUploadPreset(ObjectUtils.asMap("name", preset, "unsigned", true, "folder", "preset_folder"));
    } catch (Exception e) {
    }
    return "direct_upload_form";
}
Also used : Cloudinary(com.cloudinary.Cloudinary) PhotoUpload(cloudinary.models.PhotoUpload) IOException(java.io.IOException)

Example 4 with PhotoUpload

use of cloudinary.models.PhotoUpload in project cloudinary_java by cloudinary.

the class PhotoUploadValidator method validate.

public void validate(Object obj, Errors e) {
    ValidationUtils.rejectIfEmpty(e, "title", "title.empty");
    PhotoUpload pu = (PhotoUpload) obj;
    if (pu.getFile() == null || pu.getFile().isEmpty()) {
        if (!pu.validSignature()) {
            e.rejectValue("signature", "signature.mismatch");
        }
    }
}
Also used : PhotoUpload(cloudinary.models.PhotoUpload)

Aggregations

PhotoUpload (cloudinary.models.PhotoUpload)4 Cloudinary (com.cloudinary.Cloudinary)1 DatastoreService (com.google.appengine.api.datastore.DatastoreService)1 Entity (com.google.appengine.api.datastore.Entity)1 Key (com.google.appengine.api.datastore.Key)1 Query (com.google.appengine.api.datastore.Query)1 IOException (java.io.IOException)1