inputStream method of GridFSDBFile doesn't work with me

37 views
Skip to first unread message

Bui Kien

unread,
Mar 15, 2016, 10:11:35 AM3/15/16
to mongodb-casbah-users
Hi team,

I am working with scala 2.10 and casbah gridfs 2.5.0.
I would like to get an image from Mongodb then transform to inputStream type.
My code is:

"
// Imports just the Query DSL along with Commons and its dependencies
import com.mongodb.casbah.gridfs.GridFSDBFile
import com.mongodb.casbah.gridfs._
import com.mongodb.casbah.query.Imports._

//Import File Lib
import java.io.File
import java.io.FileInputStream

val mongoDBConnection = MongoConnection()("myTestDB")
val gridFS = GridFS(mongoDBConnection)

  // store Files
val imageFile = new File("D:/test2.jp2")
val fileInputStream=new FileInputStream(imageFile)
val gfsFile=gridFS.createFile(fileInputStream)
gfsFile.filename="test2.jp2"
gfsFile.save

// get an Image
val files = gridFS.findOne(new ObjectId("56d84ca6022b8bddf7a906b8")) // this is ObjectID of the above file "test2.jp2" 
val inputStream = files.inputStream.get()

....

"

I get an error "value inputStream is not a member of Option[com.mongodb.casbah.gridfs.GridFSDBFile]"

Anybody can tell me what happened?

Best regards.

Ross Lawley

unread,
Mar 15, 2016, 10:25:57 AM3/15/16
to mongodb-ca...@googlegroups.com
Hi,

Thats not far off, the only issue is that findOne returns an Option[GridFSDBFile].

So you should check to ensure its not None then you can do:

val inputStream = files.get.inputStream.get()

Ross

--
You received this message because you are subscribed to the Google Groups "mongodb-casbah-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-casbah-u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages