Package com.google.appengine.api.blobstore

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


      final Map<String, List<BlobKey>> blobKeysValues = blobstoreService
          .getUploads(request);
      for (final Entry<String, List<BlobKey>> blobKeyValues : blobKeysValues
          .entrySet()) {
        for (final BlobKey blobKey : blobKeyValues.getValue()) {
          final BlobInfo blobInfo = new BlobInfoFactory()
              .loadBlobInfo(blobKey);
          final long size = blobInfo.getSize();
          if (size > 0) {
            // process blob
            parameters.put(blobKeyValues.getKey(), blobKey);
          } else {
            blobstoreService.delete(blobKey);
View Full Code Here


            return null;
        }
        BlobstoreService blobstoreService =
            BlobstoreServiceFactory.getBlobstoreService();
        BlobKey blobKey = new BlobKey(blobKeyString);
        BlobInfo blobInfo = new BlobInfoFactory().loadBlobInfo(blobKey);
        response.setContentType(blobInfo.getContentType());
        response.setContentLength((int) blobInfo.getSize());
        response.setHeader(
            "Content-disposition",
            "attachment;" + blobInfo.getFilename());
        byte[] data =
            blobstoreService.fetchData(blobKey, 0, blobInfo.getSize());
        response.getOutputStream().write(data);
        response.flushBuffer();
        return null;
    }
View Full Code Here

    this.metadataDirectory = metadataDirectory;
  }

  private AttachmentMetadata computeMetadata(AttachmentId id, BlobKey blobKey) {
    try {
      BlobInfo info = blobInfoFactory.loadBlobInfo(blobKey);
      if (info != null) {
        JSONObject data = new JSONObject();
        data.put("size", info.getSize());
        String mimeType = info.getContentType();
        data.put("mimeType", mimeType);
        data.put("filename", info.getFilename());
        if (mimeType.startsWith("image/")) {
          Image img = attemptGetImageMetadata(blobstoreService, info);
          if (img != null) {
            JSONObject imgData = new JSONObject();
            imgData.put("width", img.getWidth());
View Full Code Here

    AttachmentMetadata metadata = getMetadata(id);
    if (metadata == null) {
      throw NotFoundException.withInternalMessage("Attachment id unknown: " + id);
    }
    BlobKey key = metadata.getBlobKey();
    BlobInfo info = new BlobInfoFactory().loadBlobInfo(key);
    String disposition = "attachment; filename=\""
        // TODO(ohler): Investigate what escaping we need here, and whether the
        // blobstore service has already done some escaping that we need to undo
        // (it seems to do percent-encoding on " characters).
        + info.getFilename().replace("\"", "\\\"").replace("\\", "\\\\")
        + "\"";
    log.info("Serving " + info + " with Content-Disposition: " + disposition);
    resp.setHeader("Content-Disposition", disposition);
    blobstore.serve(key, resp);
  }
View Full Code Here

    @Override public Value<Void> run(Predicate<BlobInfo> predicate, BlobKey startKey) {
      Iterator<BlobInfo> infos = new BlobInfoFactory().queryBlobInfosAfter(startKey);
      ImmutableList.Builder<BlobKey> toDelete = ImmutableList.builder();
      for (int i = 0; i < MAX_BLOBINFOS_SCANNED_PER_TASK && infos.hasNext(); i++) {
        BlobInfo info = infos.next();
        if (predicate.apply(info)) {
          toDelete.add(info.getBlobKey());
        }
      }
      for (List<BlobKey> partition : Lists.partition(toDelete.build(), MAX_RPCS_PER_TASK)) {
        List<BlobKey> list = ImmutableList.copyOf(partition);
        futureCall(new DeleteBlobs(), immediate(list));
View Full Code Here

    String width = req.getParameter("width");
    String height = req.getParameter("height");
    String jsonRet = null;

    if (width == null) { // first time
      BlobInfo info = new BlobInfoFactory().loadBlobInfo(blobKey);

      ImagesService imagesService = ImagesServiceFactory
          .getImagesService();

      // Try to fetch image data
      byte[] bytes;
      try {
        bytes = blobstoreService.fetchData(blobKey, 0, info.getSize());
      }
      catch ( Exception e){
        // If not possible, first resize to acceptable size
        Image bigImage = ImagesServiceFactory.makeImageFromBlob(blobKey);
        Transform initialResize = ImagesServiceFactory.makeResize(1024, 4000);
View Full Code Here

        Iterator<BlobInfo> iterator = null;
       
        iterator = new BlobInfoFactory().queryBlobInfos();
        while ( iterator.hasNext())
        {
          BlobInfo bi = iterator.next();
          //System.out.println( bi.getFilename() +":" + bi.getBlobKey());
        }
        //Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);
        //Set set = blobs.keySet();
       
View Full Code Here

  @Test
  public void testImagesServiceFromBlob() throws IOException{
    BlobKey key = persistBlob();
   
    Image i = (Image) ImagesServiceFactory.makeImageFromBlob(new BlobKey("abc"));
    BlobInfo blobInfo = new BlobInfoFactory().loadBlobInfo(key);
    if( blobInfo != null && blobInfo.getSize() > 0){
      System.out.println("Exists");
    } else {
      System.out.println("Does not exist");
    }
   
View Full Code Here

        assertNotNull("blobKey should not be null", blobKey);

        String contents = getFileContents(blobKey);
        assertEquals(new String(UPLOADED_CONTENT), contents);

        BlobInfo blobInfo = UploadHandlerServlet.getLastUploadedBlobInfo();
        assertNotNull("blobInfo should not be null", blobInfo);
        assertEquals(blobKey, blobInfo.getBlobKey());
        assertEquals(FILENAME, blobInfo.getFilename());
        assertEquals(CONTENT_TYPE, blobInfo.getContentType());
        assertEquals(UPLOADED_CONTENT.length, blobInfo.getSize());
        assertEquals(MD5_HASH, blobInfo.getMd5Hash());

        FileInfo fileInfo = UploadHandlerServlet.getLastUploadedFileInfo();
        assertNotNull("fileInfo should not be null", fileInfo);
        assertEquals(FILENAME, fileInfo.getFilename());
        assertEquals(CONTENT_TYPE, fileInfo.getContentType());
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.