Package com.google.appengine.api.blobstore

Examples of com.google.appengine.api.blobstore.BlobInfoFactory


    for (int i = 0; i < recordsCount; i++) {
      writeChannel.write(ByteBuffer.wrap(record.getBytes()));
    }
    writeChannel.closeFinally();
    blobKey = fileService.getBlobKey(blobFile);
    blobSize = new BlobInfoFactory().loadBlobInfo(blobKey).getSize();
  }
View Full Code Here


    public long getSize() {
      BlobKey key = getKey();
      if (key == null)
        return 0;
      BlobInfo info = new BlobInfoFactory().loadBlobInfo(key);
      if (info == null)
        return 0;
      return info.getSize();
    }
View Full Code Here

  public static String getUrl() {
    return BlobstoreServiceFactory.getBlobstoreService().createUploadUrl("/upload");
  }

  public static String getFilename(BlobKey blobKey) {
    return new BlobInfoFactory().loadBlobInfo(blobKey).getFilename();
  }
View Full Code Here

   * Order is preserved.
   * @param keyStrings - list of blobkeys as Strings
   * @return - list of BlobInfos in the same order as the blob keys.
   */
  public static List<BlobInfo> loadBlobInfos(List<String> keyStrings) {
    BlobInfoFactory infoFactory = new BlobInfoFactory();
    List<BlobInfo> blobInfos = new LinkedList<BlobInfo>();
    for (String keyString : keyStrings) {
      log.info("getting blob");
      BlobInfo blobInfo = infoFactory.loadBlobInfo(new BlobKey(keyString));
      log.info("got blob");
      if (blobInfo == null) {
        log.severe("Could not load BlobInfo from BlobKey " + keyString);
        continue;
      }
View Full Code Here

    }

    if (null == blobInfoEntity) {
      return null;
    }
    BlobInfo blobInfo = new BlobInfoFactory(datastoreService).createBlobInfo(blobInfoEntity);
    return blobInfo.getBlobKey();
  }
View Full Code Here

      String date = req.getParameter("date");

      BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
      Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);

      BlobInfoFactory blobInfoFactory = new BlobInfoFactory();

      long maxPhotoSize = adminConfigDao.getMaxPhotoSize();

      ArrayList<BlobKey> validSubmissionKeys = new ArrayList<BlobKey>();
      for (Entry<String, BlobKey> entry : blobs.entrySet()) {
        BlobKey blobKey = entry.getValue();

        BlobInfo blobInfo = blobInfoFactory.loadBlobInfo(blobKey);
        String contentType = blobInfo.getContentType().toLowerCase();
        long size = blobInfo.getSize();

        if (!contentType.startsWith("image/")) {
          blobstoreService.delete(blobKey);
          LOG.warning(String.format("Uploaded file has content type '%s'; skipping.", contentType));
          continue;
        }

        if ((size > maxPhotoSize) || (size == 0)) {
          blobstoreService.delete(blobKey);
          LOG.warning(String.format("Uploaded file is %d bytes; skipping.", size));
          continue;
        }

        validSubmissionKeys.add(blobKey);
      }

      if (validSubmissionKeys.size() > 0) {
        // PhotoSubmission represents the metadata of a set of photo entries
        PhotoSubmission photoSubmission =
            new PhotoSubmission(Long.parseLong(assignmentId), articleUrl, author, email,
                phoneNumber, title, description, location, date, validSubmissionKeys.size());
       
        if (!util.isNullOrEmpty(latitude) && !util.isNullOrEmpty(longitude)) {
          try {
            photoSubmission.setLatitude(Double.parseDouble(latitude));
            photoSubmission.setLongitude(Double.parseDouble(longitude));
          } catch (NumberFormatException e) {
            LOG.log(Level.WARNING, "Couldn't parse lat/long.", e);
          }
        }
       
        pmfUtil.persistJdo(photoSubmission);
        String submissionId = photoSubmission.getId();

        for (BlobKey blobKey : validSubmissionKeys) {
          BlobInfo blobInfo = blobInfoFactory.loadBlobInfo(blobKey);

          PhotoEntry photoEntry = new PhotoEntry(submissionId, blobKey, blobInfo.getContentType());
          photoEntry.setOriginalFileSize(blobInfo.getSize());
          photoEntry.setOriginalFileName(blobInfo.getFilename());
         
View Full Code Here

          default: blobKey = new BlobKey(b.getCsvUrl1()); }
        //BlobKey blobKey2 = new BlobKey("wWN4LMO8okJ-zlmkdQk8Bg");
      //System.out.println("overriding returned key:" + blobKey.getKeyString() + " with static key: " + blobKey2.getKeyString());
        System.out.println("sending blob key: " + blobKey.getKeyString());
        resp.setContentType("application/x-download");
        BlobInfoFactory bif = new BlobInfoFactory();
        String fileName = bif.loadBlobInfo(blobKey).getFilename();
        resp.setHeader("Content-Disposition", "attachment; filename=" + fileName);
        blobstoreService.serve(blobKey, resp);
  }
View Full Code Here

    }

    if (null == blobInfoEntity) {
      return null;
    }
    BlobInfo blobInfo = new BlobInfoFactory(datastoreService).createBlobInfo(blobInfoEntity);
    return blobInfo.getBlobKey();
  }
View Full Code Here

                .withMaxUploadSizeBytesPerBlob(1024L * 1024L * 1024L)
                .maxUploadSizeBytes(10L * 1024L * 1024L * 1024L);
        String uploadUrl = blobstoreService.createUploadUrl("/upload", uploadOptions);

        DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
        BlobInfoFactory blobInfoFactory = new BlobInfoFactory();
        List<Map<String, Object>> uploads = new ArrayList<Map<String, Object>>();

        Key userGroupKey = KeyFactory.createKey("UserUploadGroup", user.getEmail());
        Query q = new Query("UserUpload").setAncestor(userGroupKey);
        q.addFilter("user", Query.FilterOperator.EQUAL, user);
        PreparedQuery pq = ds.prepare(q);
        Iterable<Entity> results = pq.asIterable();
        for (Entity result : results) {
            Map<String, Object> upload = new HashMap<String, Object>();
            upload.put("description", (String) result.getProperty("description"));
            BlobKey blobKey = (BlobKey) result.getProperty("upload");
            upload.put("blob", blobInfoFactory.loadBlobInfo(blobKey));
            upload.put("uploadKey", KeyFactory.keyToString(result.getKey()));
            uploads.add(upload);
        }
               
        req.setAttribute("user", user);
View Full Code Here

import javax.servlet.http.HttpServletResponse;

public class Files extends MeApi {
 
  public static void serve(String key) throws LockException, IOException {
    BlobInfoFactory infoFactory = new BlobInfoFactory();
    BlobKey blobKey = new BlobKey(key);
    BlobInfo blobInfo = infoFactory.loadBlobInfo(blobKey);
    if(blobInfo==null) notFound();
    response.setContentTypeIfNotSet(blobInfo.getContentType());
    FileService fileService = FileServiceFactory.getFileService();
    AppEngineFile file = fileService.getBlobFile(blobKey);
    boolean lock = false;
View Full Code Here

TOP

Related Classes of com.google.appengine.api.blobstore.BlobInfoFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.