How to get the path of a file saved in blobstore ?

97 views
Skip to first unread message

anuja bothra

unread,
Nov 14, 2013, 4:25:02 AM11/14/13
to google-a...@googlegroups.com
Hi,

I have data in an excel sheet.
I need to read that data and save it to the datastore.

I am able to upload the excel to blobstore.
How do I get the excel file path to pass to POI (so that I can read the cell contents) ? 
My code is in Java

Thanks,
Anuja 

Alejandro González Rodrigo

unread,
Nov 14, 2013, 4:54:58 AM11/14/13
to google-a...@googlegroups.com
Hello Anuja,

When you upload a file to the blobstore, in the /_ah/upload callback you can grab the BlobKey that was uploaded:

BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(request);
BlobKey blobKey = blobs.get("file").get(0);

You need that blobkey to access the file again. If you want to accecss the file later, you might want to store it somewhere in the datastore.

With the BlobKey you can retrieve a byte[] of the file to do whatever you want:

byte[] file = blobstoreService.fetchData(blobKey, 0, BlobstoreService.MAX_BLOB_FETCH_SIZE-1);


Hopes that helps.
Good luck!



 


2013/11/14 anuja bothra <anuja...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-appengine.
For more options, visit https://groups.google.com/groups/opt_out.



--
 

If you have a dream we can write the code




anuja bothra

unread,
Nov 14, 2013, 5:07:16 AM11/14/13
to google-a...@googlegroups.com
I actually wanted to parse the file in POI since I already had written code for that in a local app.

FileInputStream myInput = new FileInputStream(filePath);
POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);

I need the "filePath" (the excel file's path) so that I can just pass that and reuse the code that I had already written.
Is that not possible ?

Thanks 


--
You received this message because you are subscribed to a topic in the Google Groups "Google App Engine" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-appengine/DBfFbG4NVhY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-appengi...@googlegroups.com.

Alejandro González Rodrigo

unread,
Nov 14, 2013, 5:22:45 AM11/14/13
to google-a...@googlegroups.com
Hello Anuja,

No, that is not possible because the actual file is not in the filesystem. But with the byte[] you can easily get a InputStream checkout: http://stackoverflow.com/questions/1802123/can-we-convert-a-byte-array-into-an-inputstream-in-java

InputStream myInputStream = new ByteArrayInputStream(file);
POIFSFileSystem myFileSystem = new POIFSFileSystem(myInputStream);



2013/11/14 anuja bothra <anuja...@gmail.com>

anuja bothra

unread,
Nov 14, 2013, 6:38:05 AM11/14/13
to google-a...@googlegroups.com
Hey Thanks Alejandro !!
Reply all
Reply to author
Forward
0 new messages