Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-724

Downloading files from gridfs does not match uploaded data

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • 0.2.0
    • Affects Version/s: 0.1.0
    • Component/s: GridFS
    • Labels:
      None
    • Environment:
      mongodb v3.6.9
      ubuntu1604

      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.

       

        1. main.go
          2 kB
          Ronnie van der Veen

            Assignee:
            devin.hilly@mongodb.com Devin Hilly (Inactive)
            Reporter:
            ronnie@sortd.com Ronnie van der Veen
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: