本文整理汇总了Java中com.google.appengine.api.blobstore.BlobInfoFactory.loadBlobInfo方法的典型用法代码示例。如果您正苦于以下问题:Java BlobInfoFactory.loadBlobInfo方法的具体用法?Java BlobInfoFactory.loadBlobInfo怎么用?Java BlobInfoFactory.loadBlobInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.appengine.api.blobstore.BlobInfoFactory
的用法示例。
在下文中一共展示了BlobInfoFactory.loadBlobInfo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFileInfo
import com.google.appengine.api.blobstore.BlobInfoFactory; //导入方法依赖的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;
}
示例2: doGet
import com.google.appengine.api.blobstore.BlobInfoFactory; //导入方法依赖的package包/类
/**
* Respond to servlet GET requests
*/
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
// Lets check the action required by the jsp
String message = req.getParameter("msg");
String action = req.getParameter("action");
if (message.equals("success")) {
// We return information about the file in JSON format
if (action.equalsIgnoreCase("upload")) {
String type = req.getParameter("type");
String datastoreObjectKeyString =
req.getParameter("datastoreObjectKey");
Key datastoreObjectKey = KeyFactory.stringToKey(datastoreObjectKeyString);
BlobKey fileKey = null;
String fileKeyString = null;
String jsonString = null;
// Check type
if (type.equalsIgnoreCase("audio_music") ||
type.equalsIgnoreCase("audio_voice")) {
StationAudio stationAudio =
StationAudioManager.getStationAudio(datastoreObjectKey);
fileKey = stationAudio.getStationAudioMultimediaContent();
}
else if (type.equalsIgnoreCase("image")) {
StationImage stationImage =
StationImageManager.getStationImage(datastoreObjectKey);
fileKey = stationImage.getStationImageMultimediaContent();
}
fileKeyString = fileKey.getKeyString();
BlobInfoFactory bif = new BlobInfoFactory();
BlobInfo blobInfo = bif.loadBlobInfo(fileKey);
String fileName = blobInfo.getFilename();
jsonString = "{" + "\n" +
"\"datastoreObjectKey\":" + "\"" + datastoreObjectKeyString + "\"," + "\n" +
"\"fileKey\":" + "\"" + fileKeyString + "\"," + "\n" +
"\"fileName\":" + "\"" + fileName + "\"\n" +
"}";
log.info("jsonString: " + jsonString);
resp.setContentType("application/json;charset=UTF-8");
resp.setCharacterEncoding("UTF-8");
resp.getWriter().println(jsonString);
}
else if (action.equals("delete")){
resp.getWriter().println("File deleted successfully.");
}
}
}
示例3: doPost
import com.google.appengine.api.blobstore.BlobInfoFactory; //导入方法依赖的package包/类
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws
IOException {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);
if (blobs.keySet().isEmpty()) {
resp.sendRedirect("/?error=" +
URLEncoder.encode("No file uploaded", "UTF-8"));
return;
}
Iterator<String> names = blobs.keySet().iterator();
String blobName = names.next();
BlobKey blobKey = blobs.get(blobName);
if (user == null) {
blobstoreService.delete(blobKey);
resp.sendRedirect("/?error=" +
URLEncoder.encode("Must be logged in to upload", "UTF-8"));
return;
}
BlobInfoFactory blobInfoFactory = new BlobInfoFactory();
BlobInfo blobInfo = blobInfoFactory.loadBlobInfo(blobKey);
String contentType = blobInfo.getContentType();
long size = blobInfo.getSize();
Date creation = blobInfo.getCreation();
String fileName = blobInfo.getFilename();
String title = req.getParameter("title");
String description = req.getParameter("description");
boolean isShared = "public".equalsIgnoreCase(req.getParameter("share"));
try {
MediaObject mediaObj = new MediaObject(user, blobKey, creation,
contentType, fileName, size, title, description, isShared);
PMF.get().getPersistenceManager().makePersistent(mediaObj);
resp.sendRedirect("/");
} catch (Exception e) {
blobstoreService.delete(blobKey);
resp.sendRedirect("/?error=" +
URLEncoder.encode("Object save failed: " + e.getMessage(), "UTF-8"));
}
}