[gridfs] Type mismatch (DefaultFileToSave and FileToSave)

101 views
Skip to first unread message

Gaëtan Rizio

unread,
Jan 24, 2016, 3:06:15 PM1/24/16
to ReactiveMongo - http://reactivemongo.org
Hello everyone,

I would like to use GridFS of reactivemongo, but I have an error at compile time.

My code is:

// Usage of Source from Akka Stream and Http, transformed into Enumerator
case InsertFileInfo(uploadInfo: UploadInfo, id: BSONObjectID, gfs: GridFS[_]) =>
val enumerator: Enumerator[Array[Byte]] = StreamUtils.sourceToEnumerator(uploadInfo.httpEntity.dataBytes).map(_.toArray[Byte])
val fileToSave: DefaultFileToSave = DefaultFileToSave(
  id.stringify,
  contentType = Some(uploadInfo.httpEntity.contentType.toString())
)
gfs.save(enumerator, fileToSave)

When I compile (in my IDE or with sbt), I end up with following error on last line:

type mismatch;
found  
: reactivemongo.api.gridfs.DefaultFileToSave
required
: reactivemongo.api.gridfs.FileToSave[gfs.pack.type,?]

I do not understand the error because DefaultFileToSave is a subtype of FileToSave.

If I use the code from https://github.com/ReactiveMongo/ReactiveMongo/blob/master/driver/samples/GridFSSample.scala (see below), I also end up with the same error.

// metadata for the file we are going to put in the store
val metadata = DefaultFileToSave(
  "mongodb-osx-x86_64-2.4.0-rc3.tgz",
  contentType = Some("application/x-compressed"))

// enumerator of the file contents
val enumerator = Enumerator.fromFile(new File("/Users/sgo/Downloads/mongodb-osx-x86_64-2.4.0-rc3.tgz"))

// ok, save the file and attach a callback when the operation is done
gfs.save(enumerator, metadata).onComplete {
  case Success(file) =>
    println(s"successfully saved file of id ${file.id}")
  case Failure(e) =>
    println("exception while saving the file!")
    e.printStackTrace()
}

Thank you for your help.

Cédric Chantepie

unread,
Jan 24, 2016, 7:19:47 PM1/24/16
to ReactiveMongo - http://reactivemongo.org

Gaëtan Rizio

unread,
Jan 26, 2016, 1:29:03 PM1/26/16
to ReactiveMongo - http://reactivemongo.org
I do not use play, so I cannot use helpers from the first link.
I downloaded the ReactiveMongo project, and I have the exact same error.

Thank you for your answer.
Reply all
Reply to author
Forward
0 new messages