SergejJurecko/erlmongo

Problem with reading file from GridFS

Closed this issue · 7 comments

tgrk commented

Hello, me again :) While I was trying to read file from GridFS (storing works like a charm) I face arity error.

Code

FilePid = Db:gfsOpen(#gfs_file{docid = DocId}).
Bin = Db:gfsRead(FilePid, 1000).

SASL error message

=ERROR REPORT==== 15-Apr-2010::20:29:01 ===
Error in process <0.238.0> with exit value: {badarith,[{mongodb,gfs_proc,2}]}

I quickly looked at source code, but with no luck. What am I missing? I followed code from readme file.

Best Regards,
tgrk

Should be fixed

tgrk commented

After checkout and recompilation and running same code I got this error:
Reason: {badarg,[{mongoapi,gfsRead,3}

Thanks for quick reply and help.

tgrk

In that case I need to see some more code because I don't know how to reproduce the bug.

This works (I read docid with mongo console):
w(Mong,File) ->
P = Mong:gfsNew("myfile"),
{ok, Bin} = file:read_file(File),
Mong:gfsWrite(P,Bin),
Mong:gfsClose(P).

r(Mong) ->
    P1 = Mong:gfsOpen(#gfs_file{docid = {oid, <<"00075aba140c1fa34b000003">>}}),
    Bin = Mong:gfsRead(P1,100000000),
    Mong:gfsClose(P1),
    Bin.
tgrk commented

Thank you it woks just fine now. I was passing bad size argument to gfsRead function.

What's the meaning of gfsRead() second parameter ?

I can't read all the file in-memory, how could I read the file peace-by-peace ?

Best regards !

That is what the second parameter does. How many bytes to return

sure, that was a stupid question.

Thanks.