简体   繁体   中英

How to use blobKey to pull out the names,content/type and size of the file from blob store in Google app engine?

As i gone through some of the examples i didn't find a right way to accomplish this logic

so, Here im trying to upload a file in blob store,by using the key of that file im unable to retrieve the name of the file,content type like so...

here is the index page :

index.jsp page

   <%
    BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
   %>
 <form action="<%= blobstoreService.createUploadUrl("/upload") %>" 
       method="post"          
       enctype="multipart/form-data">
   <input type="file" name="myFile" id="upload" multiple/><br>
   <input type="submit" value="submit form">
   </form>

upload .java

   DatastoreService ds = DatastoreServiceFactory.getDatastoreService()    ;
   Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);
   BlobKey blobKey = blobs.get("myFile");

   res.sendRedirect("/serve?blob-key=" + blobKey.getKeyString());

BlobstoreServlet.java

    BlobKey blobKey = new BlobKey(req.getParameter("blob-key"));
    blobstoreService.serve(blobKey, res);

so while running it automatically creating an entity name blobinfo where i can find all the details but unable to retrieve from there. In upload.java, able to find blobKey.toString which is the key exactly.so here is the point with the help of the key i cannot fetch the filed of the file.

Use this:

private BlobInfoFactory infoFactory = new BlobInfoFactory();

BlobKey blobKey = new BlobKey(req.getParameter("blob-key"));
BlobInfo info = infoFactory.loadBlobInfo(blobKey);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM