Can't read files from BlobStore
-
27-10-2019 - |
Question
I have been trying to write and read files directly from the BlobStore, but it just doesnt work.
The issue is I open the file like file = fileService.getBlobFile(blobKey);
and it doesn't throw any exception but right in the next line I call readChannel = fileService.openReadChannel(file, false);
and that one throws a FileNotFoundException.
I'm confused as to why the first line did not throw the exception.
Unfortunately no one answered that question.
Solution
I haven't had any problems with writes or deletes, but I too get a FileNotFoundException
when using openReadChannel(...)
with an AppEngineFile
.
I've tried using an AppEngineFile
created from its constructor taking a complete path. I've tried using an AppEngineFile
obtained from getBlobFile(...)
like you do above. Either way, when the AppEngineFile
is passed to openReadChannel(...)
a FileNotFoundException
is thrown.
My workaround was to let BlobstoreService.serve(...)
do all the work of reading and sending the file. I suspect that using the FileService
to read from an AppEngineFile
isn't supported yet (I'm using 1.6.0), so reads must be done via the BlobstoreService
(serve(...)
, fetchData(...)
, BlobstoreInputStream
).