Package com.google.appengine.api.blobstore

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


    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 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

      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());
         
          pmfUtil.persistJdo(photoEntry);
        }
       
        Queue queue = QueueFactory.getDefaultQueue();
View Full Code Here

    }

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

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;
    FileReadChannel readChannel = fileService.openReadChannel(file, lock);
    InputStream inputStream = Channels.newInputStream(readChannel);
View Full Code Here

          DatastoreServiceFactory.getDatastoreService());
      Iterator<BlobInfo> i = bif.queryBlobInfos();
      List<BlobInfo> res = new ArrayList();
      // System.out.println("VIEW BLOB BEGIN");
      while (i.hasNext()) {
        BlobInfo bi = i.next();
        res.add(bi);
        // System.out.println("RES " + bi.getBlobKey().getKeyString());
      }

      long l0 = System.currentTimeMillis();
View Full Code Here

  }

  public static byte[] getMediaFromBlob(String key) {
    byte[] byteArray = null;
    BlobKey blobKey = new BlobKey(key);
    BlobInfo blobInfo = new BlobInfoFactory().loadBlobInfo(blobKey);
    BlobstoreInputStream stream;
    try {
      stream = new BlobstoreInputStream(blobKey);
      byteArray = new byte[(int) blobInfo.getSize()];
      stream.read(byteArray);
    } catch (IOException e) {
      e.printStackTrace();
    }
    return byteArray;
View Full Code Here

      response.setStatus(HttpServletResponse.SC_NOT_FOUND);
      LOGGER.warning("No blob found by filename " + fileName);

    } else {

      final BlobInfo blobInfo = new BlobInfoFactory()
          .loadBlobInfo(blobKey);
      if (blobInfo != null && blobInfo.getSize() > 0) {
        // process blob
        this.blobstoreService.serve(blobKey, response);
      } else {
        // return a not found error
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
View Full Code Here

    try {

      final BlobstoreService blobstoreService = BlobstoreServiceFactory
          .getBlobstoreService();

      BlobInfo info = new BlobInfoFactory().loadBlobInfo(csvBlobKey);

      byte[] bytes = blobstoreService.fetchData(csvBlobKey, 0,
          info.getSize());

      final ZipInputStream zipIn = new ZipInputStream(
          new ByteArrayInputStream(bytes));

      return zipIn;
View Full Code Here

TOP

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

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.