See attached main.go file
- it reads a file from /tmp/infile and uploads it to GridFS
- downloads it from GridFS and writes it to /tmp/outfile
I'd expect the input and output files to be the same size and have the same content, but for file sizes smaller than the default chunksize the downloaded file seems to be "padded" so it ends up being 256kb.
For big files (say 12MB) the resulting outfile does not match the infile. The size is often smaller, and big chunks of data just seem to be nulls instead of the actual file data.
I also had issues uploading a 16MB video file, then the UploadFromStream returns the following error:
2018/12/19 16:21:37 Uploading to mongo2018/12/19 16:21:37 Uploading to mongopanic: runtime error: index out of range
goroutine 1 [running]:github.com/mongodb/mongo-go-driver/mongo/gridfs.(*UploadStream).uploadChunks(0xc0000bc2d0, 0x985940, 0xc0001680c0, 0x985940, 0xc0001680c0) /pkg/mod/github.com/mongodb/mongo-go-driver@v0.1.0/mongo/gridfs/upload_stream.go:163 +0x7bfgithub.com/mongodb/mongo-go-driver/mongo/gridfs.(*UploadStream).Close(0xc0000bc2d0, 0x0, 0x0) /pkg/mod/github.com/mongodb/mongo-go-driver@v0.1.0/mongo/gridfs/upload_stream.go:70 +0xfdgithub.com/mongodb/mongo-go-driver/mongo/gridfs.(*Bucket).UploadFromStreamWithID(0xc0001be000, 0x2bb9ac88f1531a5c, 0xc0c125834f, 0x85a272, 0x9, 0x9812c0, 0xc0001ae000, 0x0, 0x0, 0x0, ...) /pkg/mod/github.com/mongodb/mongo-go-driver@v0.1.0/mongo/gridfs/bucket.go:174 +0x1aegithub.com/mongodb/mongo-go-driver/mongo/gridfs.(*Bucket).UploadFromStream(0xc0001be000, 0x85a272, 0x9, 0x9812c0, 0xc0001ae000, 0x0, 0x0, 0x0, 0x0, 0xc000000000, ...) /pkg/mod/github.com/mongodb/mongo-go-driver@v0.1.0/mongo/gridfs/bucket.go:138 +0xd1main.Set(0xc0001a2060, 0x85a272, 0x9, 0x9812c0, 0xc0001ae000, 0x0, 0xc0001a2060) /src/bitbucket.org/mybeat/sortd_go/cmd/testmongo/main.go:70 +0x17bmain.main() /src/bitbucket.org/mybeat/sortd_go/cmd/testmongo/main.go:40 +0x33e
I ran the same test using the mgo driver and there it worked as expected.