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();
}
Aggregations