mongodb - Can not retrieve file from gridFs using the java driver (but can using python) -


note; we've rewritten backend in python now, though still nice know did wrong, it's not big of thing anymore.

i've got known file in database has following objectid "5251ad0d56c02c34fbad2a3d"

i know it's there, since can inspect both mongo cli client , pymongo:

>>> import pymongo, gridfs, bson >>> client = pymongo.mongoclient() >>> db = client['playtest'] >>> fs = gridfs.gridfs(db, 'attachments') >>> gridout = fs.get(bson.objectid.objectid("5251ad0d56c02c34fbad2a3d")) >>> gridout.filename u'vasalis-03.png' >>> 

however when try retrieve using java following code

import com.mongodb.basicdbobject; import com.mongodb.db; import com.mongodb.dbcollection; import com.mongodb.dbobject; import com.mongodb.gridfs.gridfs; import com.mongodb.gridfs.gridfsdbfile; import com.mongodb.gridfs.gridfsinputfile; import com.mongodb.mongoclient; import org.bson.types.objectid;  import java.io.file;  public class retrievefiletest {   public static void main(string[] args) throws exception {     mongoclient mongoclient = new mongoclient();     db db = mongoclient.getdb( "playtest" );     gridfs gfs = new gridfs(db, "attachments");      system.out.println("getting file: " + args[0]);     objectid fileid = new objectid(args[0]);     gridfsdbfile gfsfile = gfs.findone(fileid);     file outfile = new file(gfsfile.getfilename());     gfsfile.writeto(outfile);   } } 

i error message:

getting file: 5251ad0d56c02c34fbad2a3d oct 06, 2013 7:01:45 pm com.mongodb.dbportpool goterror warning: emptying dbportpool /127.0.0.1:27017 b/c of error java.lang.classcastexception: com.mongodb.basicdblist cannot cast java.lang.string     @ com.mongodb.gridfs.gridfsfile.put(gridfsfile.java:192)     @ org.bson.basicbsoncallback.objectstart(basicbsoncallback.java:69)     @ com.mongodb.defaultdbcallback.objectstart(defaultdbcallback.java:64)     @ org.bson.basicbsoncallback.arraystart(basicbsoncallback.java:88)     @ org.bson.basicbsondecoder.decodeelement(basicbsondecoder.java:195)     @ org.bson.basicbsondecoder._decode(basicbsondecoder.java:79)     @ org.bson.basicbsondecoder.decode(basicbsondecoder.java:57)     @ com.mongodb.defaultdbdecoder.decode(defaultdbdecoder.java:61)     @ com.mongodb.response.<init>(response.java:83)     @ com.mongodb.dbport.go(dbport.java:142)     @ com.mongodb.dbport.call(dbport.java:92)     @ com.mongodb.dbtcpconnector.innercall(dbtcpconnector.java:244)     @ com.mongodb.dbtcpconnector.call(dbtcpconnector.java:216)     @ com.mongodb.dbapilayer$mycollection.__find(dbapilayer.java:288)     @ com.mongodb.dbapilayer$mycollection.__find(dbapilayer.java:273)     @ com.mongodb.dbcollection.findone(dbcollection.java:728)     @ com.mongodb.dbcollection.findone(dbcollection.java:670)     @ com.mongodb.gridfs.gridfs.findone(gridfs.java:191)     @ com.mongodb.gridfs.gridfs.findone(gridfs.java:173)     @ nl.lntng.storm_project.retrievefiletest.main(retrievefiletest.java:30)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:606)     @ org.codehaus.mojo.exec.execjavamojo$1.run(execjavamojo.java:297)     @ java.lang.thread.run(thread.java:724) 

and have no idea it.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -