// 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)
type mismatch;
found : reactivemongo.api.gridfs.DefaultFileToSave
required: reactivemongo.api.gridfs.FileToSave[gfs.pack.type,?]
// metadata for the file we are going to put in the storeval metadata = DefaultFileToSave( "mongodb-osx-x86_64-2.4.0-rc3.tgz", contentType = Some("application/x-compressed"))
// enumerator of the file contentsval 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 donegfs.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()}