[GODRIVER-1232] downloadStream result "nil" Created: 13/Aug/19  Updated: 15/Aug/19  Resolved: 15/Aug/19

Status: Closed
Project: Go Driver
Component/s: GridFS
Affects Version/s: 1.0.4
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Tufan Atak Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

var dodata []byte
data := []byte("abc")
uploadStream, err := buck.OpenUploadStream(
"test.txt",
)
if err != nil {
log.Println(err)
log.Fatalln("Error opening uploadStream")
}
defer uploadStream.Close()
fileSize, err := uploadStream.Write(data)
if err != nil {
log.Fatalln("Error writing uploadStream")
}
fileID := uploadStream.FileID
fmt.Fprintf(w, "Write file to DB was succesful, File size: %d", fileSize)
fmt.Fprintf(w, ", FileID: %d", fileID)
 
downloadStream, err := buck.OpenDownloadStreamByName("test.txt")
if err != nil {
log.Fatalln(err)
}
defer downloadStream.Close()
downSize, err := downloadStream.Read(dodata)
if err != nil {
log.Fatalln(err)
}
fmt.Fprintf(w, "Download file from DB was succesful, File size: %d", downSize)
fmt.Fprintf(w, " Content: %d", dodata)


Hello mongoDB Team
I have an issue with golang driver and mongoDB. I want to download files from gridfs with downloadStream. Upload wasn't a problem,but if I try to download as you see in the code above, i will get the result like below .But it wasn't successful, because my log.Printf shows me nil.

Write file to DB was succesful, File size: 3, FileID: [93 82 190 120 106 41 138 138 124 134 194 179]Download file from DB was succesful, File size: 0 Content: []




 Comments   
Comment by Kristofer Brandow (Inactive) [ 15/Aug/19 ]

Hi atak@labmed.de,

The gridfs.DownloadStream type implements the io.Reader interface. The The io.Reader interface in Go will copy up to the length of the []byte provided, since the []byte provided has a zero length, no bytes are copied into it. For further details please see the io.Reader documentation.

Additionally, please note that this project is for reporting bugs or feature suggestions for the driver. For MongoDB-related support discussion please post on the mongodb-user group or Stack Overflow with the mongodb tag. A question like this involving more discussion would be best posted on the mongodb-users group.

--Kris

Generated at Thu Feb 08 08:35:58 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.