Open damienmg opened 10 years ago
Is it still an issue? I'm using
And it appears to save/load files using GridFsTemplate.
Hi,
I didn't test, but I'm glad if all is fine now :)
UPDATE: This appears to have been fixed in 1.6.3, which would agree with the above comment by ml054. I just re-tested with 1.6.4 and the failing images now succeed.
I have had intermittent failures when saving and retrieving binary (.png) files. It's a bit strange (without knowing implementation details) that it's always the same files that fail consistently... I've tried it with both 1.5.8 and 1.6.2.
I'm attaching an example - one is the direct output of an ImageIO operation, and the other is the same binary content after being saved & retrieved from Fongo via the method call:
gridFsOperations.store(inputStream, assetId);
If you use GridFs through com.mongodb.client.gridfs package classes, you run into the problem that fongo believes "fs.chunks" and "fs.files" are invalid collection names. I dirty fixed that in my project using the following code. Now it seems to work alright)))
package com.github.fakemongo
import com.mongodb.MongoNamespace import com.mongodb.WriteConcern import com.mongodb.binding.WriteBinding import com.mongodb.bulk.BulkWriteResult import com.mongodb.bulk.InsertRequest import com.mongodb.connection.ServerVersion import com.mongodb.operation.WriteOperation import org.bson.codecs.configuration.CodecRegistry
class FongoEx(name: String, serverVersion: ServerVersion, codecRegistry: CodecRegistry) : Fongo(name, serverVersion, codecRegistry) {
override fun
internal class WriteBindingEx(private val fongo: FongoEx) : WriteBinding {
override fun getWriteConnectionSource(): ConnectionSource = ConnectionSource(fongo)
override fun retain(): WriteBinding = this
override fun getCount(): Int = 0
override fun release() {}
}
internal class ConnectionSource(private val fongo: FongoEx) : FongoConnectionSource(fongo) {
override fun getConnection(): Connection = Connection(fongo)
}
internal class Connection(fongo: FongoEx) : FongoConnection(fongo) {
override fun insertCommand(namespace: MongoNamespace, ordered: Boolean, writeConcern: WriteConcern?,
bypassDocumentValidation: Boolean?, inserts: MutableList<InsertRequest>?): BulkWriteResult {
val effectiveBypassDocumentValidation = if (namespace.collectionName.contains('.')) true else bypassDocumentValidation
return super.insertCommand(namespace, ordered, writeConcern, effectiveBypassDocumentValidation, inserts)
}
}
}
Apparently, mongodb does translation of GridFSDBFile on the fly when reading the database which fongo does not.
Try retrieving a GridFS files and you'll get a RuntimeException "somehow didn't get a GridFSDBFile"