Package com.google.appengine.api.blobstore

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


    Preconditions.checkNotNull(entity, "Null entity");
    for (MovableProperty property : properties) {
      if (entity.hasProperty(property.getMovedPropertyName())) {
        Preconditions.checkArgument(!entity.hasProperty(property.getPropertyName()),
            "Entity %s already has property %s", entity, property);
        BlobKey blobKey = new BlobKey(
            (String) entity.getProperty(property.getMovedPropertyName()));
        byte[] bytes;
        try {
          bytes = slurp(blobKey);
        } catch (IOException e) {
View Full Code Here


   */
  public void postDelete(Entity entity) {
    Preconditions.checkNotNull(entity, "Null entity");
    for (MovableProperty property : properties) {
      if (entity.hasProperty(property.getMovedPropertyName())) {
        BlobKey blobKey = new BlobKey(
            (String) entity.getProperty(property.getMovedPropertyName()));
        BlobstoreServiceFactory.getBlobstoreService().delete(blobKey);
        log.info("Deleted blob for " + property + ": " + blobKey);
        listener.blobDeleted(entity.getKey(), property, blobKey);
      }
View Full Code Here

      // Special case since it would lead to an IllegalArgumentException below.
      log.info("Empty attachment, can't get image metadata: " + info);
      return null;
    }
    final int readPortion = headerBytesUpperBound;
    BlobKey key = info.getBlobKey();
    byte[] data = blobstore.fetchData(key, 0, readPortion);
    try {
      Image img = ImagesServiceFactory.makeImage(data);
      // Force the image to be processed
      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).
View Full Code Here

    }
    AttachmentMetadata metadata = getMetadata(id);
    if (metadata == null) {
      throw NotFoundException.withInternalMessage("Attachment id unknown: " + id);
    }
    BlobKey key = metadata.getBlobKey();
    // TODO(danilatos): Factor out some of this code into a separate method so that
    // thumbnails can be eagerly created at upload time.
    ThumbnailData thumbnail = thumbnailDirectory.getWithoutTx(key);

    if (thumbnail == null) {
View Full Code Here

    return e.id;
  }

  @Override
  protected ThumbnailData parse(Entity e) {
    return new ThumbnailData(new BlobKey(e.getKey().getName()),
        DatastoreUtil.getExistingProperty(e, THUMBNAIL_BYTES_PROPERTY, Blob.class).getBytes());
  }
View Full Code Here

  @Override
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(req);
    List<BlobKey> blobKeys = blobs.get(ATTACHMENT_UPLOAD_PARAM);
    log.info("blobKeys: " + blobKeys);
    BlobKey blobKey = Iterables.getOnlyElement(blobKeys);
    AttachmentId newId = rawAttachmentService.turnBlobIntoAttachment(blobKey);
    UploadResult.write(resp.getWriter(), new GxpContext(getLocale(req)),
        analyticsAccount, newId.getId());
  }
View Full Code Here

      log.info("Legacy attachment without blob key: " + id);
      blobKey = id.getId();
    }
    String metadata = DatastoreUtil.getExistingProperty(e, JSON_METADATA_PROPERTY, String.class);
    try {
      return new AttachmentMetadata(id, new BlobKey(blobKey), new JSONObject(metadata));
    } catch (JSONException je) {
      throw new DatastoreUtil.InvalidPropertyException(e, JSON_METADATA_PROPERTY,
          "Invalid json metadata: " + metadata, je);
    }
  }
View Full Code Here

                  Assert.check(expectedBytes == bytes.length, "Expected %s bytes, got %s: %s",
                      expectedBytes, bytes.length, prettyBytes(bytes));
                }
                final AppEngineFile file = dump(mimeType, filename, ByteBuffer.wrap(bytes));
                log.info("Wrote file " + file);
                BlobKey blobKey =
                    // NOTE(ohler): When running locally with unapplied jobs
                    // enabled, getBlobKey() sometimes returns null here even
                    // though it shouldn't, according to its documentation.  So
                    // we retry.  Not sure if this is needed when deployed.
                    new RetryHelper().run(
                        new RetryHelper.Body<BlobKey>() {
                          @Override public BlobKey run() throws RetryableFailure {
                            BlobKey key = getFileService().getBlobKey(file);
                            if (key != null) {
                              return key;
                            } else {
                              throw new RetryableFailure("getBlobKey(" + file + ") returned null");
                            }
View Full Code Here

    log.info("Deleting all blobs");
    return DeleteMatchingBlobs.start(new IsIntermediateMapReduceFile());
  }

  private BlobKey findBlob(String keyOrFilePath) {
    BlobKey candidateKey;
    if (keyOrFilePath.startsWith("/blobstore/")) {
      candidateKey = FileServiceFactory.getFileService()
          .getBlobKey(new AppEngineFile(keyOrFilePath));
    } else {
      candidateKey = new BlobKey(keyOrFilePath);
    }
    if (new BlobInfoFactory().loadBlobInfo(candidateKey) != null) {
      return candidateKey;
    } else {
      throw new IllegalArgumentException(
View Full Code Here

TOP

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

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.