当前位置: 首页>>代码示例>>Java>>正文


Java BlobInfo类代码示例

本文整理汇总了Java中com.google.appengine.api.blobstore.BlobInfo的典型用法代码示例。如果您正苦于以下问题:Java BlobInfo类的具体用法?Java BlobInfo怎么用?Java BlobInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BlobInfo类属于com.google.appengine.api.blobstore包,在下文中一共展示了BlobInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: serveDownload

import com.google.appengine.api.blobstore.BlobInfo; //导入依赖的package包/类
/**
 * Serves the attachment with cache control.
 *
 * @param req Only used to check the If-Modified-Since header.
 */
public void serveDownload(AttachmentId id,
    HttpServletRequest req, HttpServletResponse resp) throws IOException {
  if (maybeCached(req, resp, "download, id=" + id)) {
    return;
  }
  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);
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:27,代码来源:AttachmentService.java

示例2: attemptGetImageMetadata

import com.google.appengine.api.blobstore.BlobInfo; //导入依赖的package包/类
@Nullable private Image attemptGetImageMetadata(BlobstoreService blobstore, BlobInfo info) {
  if (info.getSize() == 0) {
    // 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();
    img.getHeight();
    return img;
  } catch (RuntimeException e) {
    log.log(Level.SEVERE, "Problem getting image metadata; ignoring", e);
    return null;
  }
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:21,代码来源:RawAttachmentService.java

示例3: assignBlobKey

import com.google.appengine.api.blobstore.BlobInfo; //导入依赖的package包/类
/**
 * Returns a new blobkey for an uploaded blob.
 * If no blob was uploaded, then null is returned.
 * @param req
 * 			: the HTTP Servlet Request from the Servlet
 * @param paramName
 * 			: the name of the HTTP blob parameter
 * @param blobStoreService
 * 			: the blobstore service initialized in the calling servlet
 * @return a new BlobKey for this blob
 */
public static BlobKey assignBlobKey(HttpServletRequest req, String paramName, 
		BlobstoreService blobstoreService) {
       java.util.Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(req);
       List<BlobKey> blobKeys = blobs.get(paramName);
       if (blobKeys != null) {
       	BlobKey blobKey = blobKeys.get(0);
           final BlobInfo blobInfo = new BlobInfoFactory().loadBlobInfo(blobKey);
           if (blobKey != null) {
           	if (blobInfo.getSize() > 0) {
           		return blobKey;
           	}
           	else {
           		blobstoreService.delete(blobKey);
           		return null;
           	}
           }
           else {
           	return null;
           }
	}
       else {
       	return null;
       }
}
 
开发者ID:gfigueroa,项目名称:internet-radio-gae,代码行数:36,代码来源:BlobUtils.java

示例4: doPost

import com.google.appengine.api.blobstore.BlobInfo; //导入依赖的package包/类
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
	String title = req.getParameter("title");

	Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(req);
	BlobKey blobKey = blobs.get("myFile").get(0);
	BlobInfo info = new BlobInfoFactory().loadBlobInfo(blobKey);

	if (blobKey == null) {
		resp.sendRedirect("/admin/resource/add.jsp?error");
	}

	Resource resource = new Resource();
	resource.setTitle(title);
	resource.setBlobKey(blobKey);
	resource.setContentType(info.getContentType());
	resource.setFileName(info.getFilename());
	resource.setSize(info.getSize());

	PersistenceManager pm = PMF.get().getPersistenceManager();
	pm.makePersistent(resource);
	pm.close();

	resp.sendRedirect("/admin/resource/");
}
 
开发者ID:santiagolizardo,项目名称:jerba,代码行数:27,代码来源:AddResourceServlet.java

示例5: getFileInfo

import com.google.appengine.api.blobstore.BlobInfo; //导入依赖的package包/类
@Override
public FileInfo getFileInfo(HttpServletRequest req) {
	Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);
    if (blobs.keySet().isEmpty()) { 
    	throw new RuntimeException("No File found"); 
    }
    Iterator<String> names = blobs.keySet().iterator();
    String blobName = names.next();
    BlobKey blobKey = blobs.get(blobName);
    BlobInfoFactory blobInfoFactory = new BlobInfoFactory();
    BlobInfo blobInfo = blobInfoFactory.loadBlobInfo(blobKey);

    FileInfo fileInfo = new FileInfo();
    fileInfo.setFileName(blobInfo.getFilename());
    fileInfo.setContentType(blobInfo.getContentType());
    fileInfo.setSize(blobInfo.getSize());
    
	return fileInfo;
}
 
开发者ID:Laesod,项目名称:binary-storage,代码行数:20,代码来源:BinaryStorageBOInBlobStoreGAEImpl.java

示例6: extractImageKey

import com.google.appengine.api.blobstore.BlobInfo; //导入依赖的package包/类
/**
 * Extracts the image metadata by the passed image key parameter.
 */
protected BlobInfo extractImageKey(String param) {
    try {
        Map<String, List<BlobInfo>> blobsMap = BlobstoreServiceFactory.getBlobstoreService().getBlobInfos(request);
        List<BlobInfo> blobs = blobsMap.get(param);

        if (blobs == null || blobs.isEmpty()) {
            data.ajaxStatus = Const.StatusMessages.NO_IMAGE_GIVEN;
            isError = true;
            return null;
        }

        BlobInfo image = blobs.get(0);
        return validateImage(image);
    } catch (IllegalStateException e) {
        return null;
    }
}
 
开发者ID:TEAMMATES,项目名称:teammates,代码行数:21,代码来源:ImageUploadAction.java

示例7: validateImage

import com.google.appengine.api.blobstore.BlobInfo; //导入依赖的package包/类
/**
 * Validates the image by size and content type.
 */
protected BlobInfo validateImage(BlobInfo image) {
    if (image.getSize() > Const.SystemParams.MAX_PROFILE_PIC_SIZE) {
        deleteImage(image.getBlobKey());
        isError = true;
        data.ajaxStatus = Const.StatusMessages.IMAGE_TOO_LARGE;
        return null;
    } else if (!image.getContentType().contains("image/")) {
        deleteImage(image.getBlobKey());
        isError = true;
        data.ajaxStatus = Const.StatusMessages.FILE_NOT_A_PICTURE;
        return null;
    }

    return image;
}
 
开发者ID:TEAMMATES,项目名称:teammates,代码行数:19,代码来源:ImageUploadAction.java

示例8: extractProfilePictureKey

import com.google.appengine.api.blobstore.BlobInfo; //导入依赖的package包/类
private BlobInfo extractProfilePictureKey() {
    try {
        Map<String, List<BlobInfo>> blobsMap = BlobstoreServiceFactory.getBlobstoreService()
                                                                      .getBlobInfos(request);
        List<BlobInfo> blobs = blobsMap.get(Const.ParamsNames.STUDENT_PROFILE_PHOTO);
        if (blobs == null || blobs.isEmpty()) {
            statusToUser.add(new StatusMessage(Const.StatusMessages.STUDENT_PROFILE_NO_PICTURE_GIVEN,
                                               StatusMessageColor.DANGER));
            isError = true;
            return null;
        }
        BlobInfo profilePic = blobs.get(0);
        return validateProfilePicture(profilePic);
    } catch (IllegalStateException e) {
        /*
         * This means the action was called directly (and not via BlobStore API callback).
         * Simply redirect to ProfilePage.
         */
        return null;
    }
}
 
开发者ID:TEAMMATES,项目名称:teammates,代码行数:22,代码来源:StudentProfilePictureUploadAction.java

示例9: validateProfilePicture

import com.google.appengine.api.blobstore.BlobInfo; //导入依赖的package包/类
private BlobInfo validateProfilePicture(BlobInfo profilePic) {
    if (profilePic.getSize() > Const.SystemParams.MAX_PROFILE_PIC_SIZE) {
        deletePicture(profilePic.getBlobKey());
        isError = true;
        statusToUser.add(new StatusMessage(Const.StatusMessages.STUDENT_PROFILE_PIC_TOO_LARGE,
                                           StatusMessageColor.DANGER));
        return null;
    } else if (!profilePic.getContentType().contains("image/")) {
        deletePicture(profilePic.getBlobKey());
        isError = true;
        statusToUser.add(new StatusMessage(Const.StatusMessages.STUDENT_PROFILE_NOT_A_PICTURE,
                                           StatusMessageColor.DANGER));
        return null;
    }

    return profilePic;
}
 
开发者ID:TEAMMATES,项目名称:teammates,代码行数:18,代码来源:StudentProfilePictureUploadAction.java

示例10: extractGroupReceiverListFileKey

import com.google.appengine.api.blobstore.BlobInfo; //导入依赖的package包/类
private BlobInfo extractGroupReceiverListFileKey() {
    try {
        Map<String, List<BlobInfo>> blobsMap = BlobstoreServiceFactory.getBlobstoreService().getBlobInfos(request);
        List<BlobInfo> blobs = blobsMap.get(Const.ParamsNames.ADMIN_EMAIL_GROUP_RECEIVER_LIST_TO_UPLOAD);

        if (blobs == null || blobs.isEmpty()) {
            data.ajaxStatus = Const.StatusMessages.NO_GROUP_RECEIVER_LIST_FILE_GIVEN;
            isError = true;
            return null;
        }

        BlobInfo groupReceiverListFile = blobs.get(0);
        return validateGroupReceiverListFile(groupReceiverListFile);
    } catch (IllegalStateException e) {
        return null;
    }
}
 
开发者ID:TEAMMATES,项目名称:teammates,代码行数:18,代码来源:AdminEmailGroupReceiverListUploadAction.java

示例11: testUploadedFileHasCorrectContent_assert

import com.google.appengine.api.blobstore.BlobInfo; //导入依赖的package包/类
@Test
@InSequence(20)
public void testUploadedFileHasCorrectContent_assert() throws Exception {
    BlobKey blobKey = UploadHandlerServlet.getLastUploadedBlobKey();
    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());
    assertEquals(UPLOADED_CONTENT.length, fileInfo.getSize());
    assertEquals(MD5_HASH, fileInfo.getMd5Hash());
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:25,代码来源:BlobstoreUploadTestBase.java

示例12: computeMetadata

import com.google.appengine.api.blobstore.BlobInfo; //导入依赖的package包/类
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());
          imgData.put("height", img.getHeight());
          data.put("image", imgData);

          JSONObject thumbData = new JSONObject();
          double ratio = resizeRatio(img);
          thumbData.put("width", ratio * img.getWidth());
          thumbData.put("height", ratio * img.getHeight());
          data.put("thumbnail", thumbData);
        }
      } else {
        // TODO(danilatos): Thumbnails for non-images
        log.info("Unimplemented: Thumbnails for non-images");
      }
      return new AttachmentMetadata(id, blobKey, data);
    }
    return null;
  } catch (JSONException e) {
    throw new Error(e);
  }
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:35,代码来源:RawAttachmentService.java

示例13: assignBlobKeys

import com.google.appengine.api.blobstore.BlobInfo; //导入依赖的package包/类
/**
 * Returns a list of blobkeys for multiple blob uploads.
 * If no blob was uploaded, then an empty list is returned.
 * @param req
 * 			: the HTTP Servlet Request from the Servlet
 * @param paramName
 * 			: the name of the HTTP blob parameter
 * @param blobStoreService
 * 			: the blobstore service initialized in the calling servlet
 * @return a list of BlobKeys
 */
public static ArrayList<BlobKey> assignBlobKeys(HttpServletRequest req, String paramName, 
		BlobstoreService blobstoreService) {
	
	ArrayList<BlobKey> finalBlobKeys = new ArrayList<BlobKey>();
	
       java.util.Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(req);
       List<BlobKey> blobKeys = blobs.get(paramName);
       if (blobKeys != null) {
       	for (BlobKey blobKey : blobKeys) {
            final BlobInfo blobInfo = new BlobInfoFactory().loadBlobInfo(blobKey);
            if (blobKey != null) {
            	if (blobInfo.getSize() > 0) {
            		finalBlobKeys.add(blobKey);
            	}
            	else {
            		blobstoreService.delete(blobKey);
            	}
            }
       	}
	}
       else {
       	return null;
       }
       
       return finalBlobKeys;
}
 
开发者ID:gfigueroa,项目名称:internet-radio-gae,代码行数:38,代码来源:BlobUtils.java

示例14: readBlobFully

import com.google.appengine.api.blobstore.BlobInfo; //导入依赖的package包/类
public static byte[] readBlobFully(BlobKey blobKey) {

		BlobstoreService blobstoreService = BlobstoreServiceFactory
				.getBlobstoreService();
		BlobInfo blobInfo = new BlobInfoFactory().loadBlobInfo(blobKey);

		if (blobInfo == null)
			return null;

		if (blobInfo.getSize() > Integer.MAX_VALUE)
			throw new RuntimeException(
					"This method can only process blobs up to "
							+ Integer.MAX_VALUE + " bytes");

		int blobSize = (int) blobInfo.getSize();
		int chunks = (int) Math
				.ceil(((double) blobSize / BlobstoreService.MAX_BLOB_FETCH_SIZE));
		int totalBytesRead = 0;
		int startPointer = 0;
		int endPointer;
		byte[] blobBytes = new byte[blobSize];

		for (int i = 0; i < chunks; i++) {

			endPointer = Math.min(blobSize - 1, startPointer
					+ BlobstoreService.MAX_BLOB_FETCH_SIZE - 1);

			byte[] bytes = blobstoreService.fetchData(blobKey, startPointer,
					endPointer);

			for (int j = 0; j < bytes.length; j++)
				blobBytes[j + totalBytesRead] = bytes[j];

			startPointer = endPointer + 1;
			totalBytesRead += bytes.length;
		}

		return blobBytes;
	}
 
开发者ID:Laesod,项目名称:binary-storage,代码行数:40,代码来源:BinaryStorageBOInBlobStoreGAEImpl.java

示例15: doPost

import com.google.appengine.api.blobstore.BlobInfo; //导入依赖的package包/类
/**
 * Registers the uploaded files in the Datastore.
 */
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) 
    throws ServletException, IOException {
  resp.setContentType("application/json");

  GsonBuilder builder = new GsonBuilder();
  Gson gson = builder.create();

  Map<String, List<BlobInfo>> blobs;
  try {
    blobs = blobstore.getBlobInfos(req);
  } catch (IllegalStateException e) {

    ErrorResponse error = new ErrorResponse();
    error.setCode(HttpServletResponse.SC_BAD_REQUEST);
    ErrorMessage message = new ErrorMessage();
    message.setMessage("Blobstore service illegal state");

    resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    resp.getWriter().print(gson.toJson(error));
    return;
  }

  List<BlobInfo> infos = blobs.get("files");
  Iterable<FileData> files = Iterables.transform(infos, blobInfoToEntity());
  Iterable<Entity> entities = Iterables.transform(files, fileDataToEntity());

  datastore.put(entities);

  resp.setStatus(HttpServletResponse.SC_OK);
  resp.getWriter().print(gson.toJson(files));
}
 
开发者ID:andrestesti,项目名称:blobstoretest,代码行数:36,代码来源:UploadServlet.java


注:本文中的com.google.appengine.api.blobstore.BlobInfo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。