Search in sources :

Example 1 with CloudStorageFileItem

use of gwtupload.server.gae.CloudStorageFileItemFactory.CloudStorageFileItem in project blogwt by billy1380.

the class ResourceUploadAction method executeAction.

/* (non-Javadoc)
	 * 
	 * @see
	 * gwtupload.server.gae.CloudStorageUploadAction#executeAction(javax.servlet
	 * .http.HttpServletRequest, java.util.List) */
@Override
public String executeAction(HttpServletRequest request, List<FileItem> sessionFiles) throws UploadActionException {
    StringBuffer resourcesJson = new StringBuffer();
    Resource resource;
    final Date now = new Date();
    for (FileItem i : sessionFiles) {
        if (!i.isFormField()) {
            resource = new Resource();
            resource.created = now;
            resource.data = "gs://" + ((CloudStorageFileItem) i).getKey().getKeyString();
            resource.description = "New uploaded file " + i.getName();
            resource.name = i.getName();
            JsonObject object = new JsonObject();
            object.addProperty("contentType", i.getContentType());
            // add it to the description
            try {
                object.addProperty("staticUrl", ImagesServiceFactory.getImagesService().getServingUrl(ServingUrlOptions.Builder.withBlobKey(((CloudStorageFileItem) i).getKey())).replaceFirst("https:\\/\\/", "//").replaceFirst("http:\\/\\/", "//"));
            } catch (Throwable e) {
            }
            resource.properties = object.toString();
            resource = ResourceServiceProvider.provide().addResource(resource);
            if (resourcesJson.length() != 0) {
                resourcesJson.append(" ");
            }
            resourcesJson.append(resource.id.toString());
        }
    }
    return resourcesJson.toString();
}
Also used : FileItem(org.apache.commons.fileupload.FileItem) CloudStorageFileItem(gwtupload.server.gae.CloudStorageFileItemFactory.CloudStorageFileItem) Resource(com.willshex.blogwt.shared.api.datatype.Resource) JsonObject(com.google.gson.JsonObject) Date(java.util.Date)

Aggregations

JsonObject (com.google.gson.JsonObject)1 Resource (com.willshex.blogwt.shared.api.datatype.Resource)1 CloudStorageFileItem (gwtupload.server.gae.CloudStorageFileItemFactory.CloudStorageFileItem)1 Date (java.util.Date)1 FileItem (org.apache.commons.fileupload.FileItem)1