Closed G2G2G2G closed 1 year ago
I created the file using dd, and copied your code, but I can't replicate this issue at all.
(or, maybe it's a browser bug? It always seems to return a 200 - OK for me) (or, did you misspell the url? like http://localhost:3000/d
?)
If I misspelled the URL how would lower sized files work? anyway could it be due to 32bit Go? the server is a small ARM SBC that is 32bit.
I went and tested both net/http servefile and gin framework. Both worked.
If I misspelled the URL how would lower sized files work?
Ah yeah, sorry, that was my mistake,
anyway could it be due to 32bit Go? the server is a small ARM SBC that is 32bit.
Yup.. that's exactly the reason. I just tried it using GOARCH=386, and it returned a 404
err := c.Download("./filetest.mp4", "wtf.mp4")
if err != nil {
log.Println(err)
}
says that the issue is that 2023/03/18 16:21:39 sendfile: file ./filetest.mp4 not found
but, if I debug it, everything seems to work in c.SendFile
file = filepath.ToSlash(file)
is set without issues, and even c.fasthttp.Request.SetRequestURI(file)
returns a 200
until Line 1667, where it serves the file via sendFileHandler(c.fasthttp)
, which returns a status of 404.. so it's likely an issue with fasthttp, and not fiber (I think, though I'm not really sure..)
@G2G2G2G have you found anything related to this issue on the fasthttp repo?
@cmd777 Yea so I posted it in their issue thread too. Not sure about debugging it or anything. I just used some several other frameworks & normal net/http to test and found none had issues.
I went with net/http since it uses virtually no RAM same as gofiber is. Gin framework used like a few MB for some reason lol (like 5-6MB while transferring) I figure if I ever am transferring a thousand files at once (probably never) it'll add up.
w.Header().Set("Content-Disposition", "attachment; filename="+strconv.Quote(fileName))
w.Header().Set("Content-Type", "application/octet-stream")
http.ServeFile(w, r, filePath)
seems to do basically the exact same thing
@gaby No I didn't look, I am completely unfamiliar with fasthttp, just use gofiber for some stuff. I posted it though as seen above
I guess this can be closed if it isn't going to be fixed here
@G2G2G2G We can keep open for now. Lets see what fasthttp says.
Fasthttp is not going to fix this as this is not a use case that fasthttp was build for at all. Anyone wanting to do this should be using net/http. But what fiber could potentially do is not use the fasthttp file API but instead use response streaming and pass the file to that itself.
Just a note for the future. I have done this before by using io.CopyBuffer
to copy from a File to a net buffer using this hack from https://github.com/golang/go/issues/16474 to avoid buffer allocations.
buf := make([]byte, 1024*1024)
io.CopyBuffer(struct{ io.Writer }{dst}, struct{ io.Reader }{src}, buf)
Bug Description
title
How to Reproduce
Steps to reproduce the behavior:
dd if=/dev/zero of=filetest.mp4 bs=10M count=210
return c.Download("./filetest.mp4", "wtf.mp4")
Expected Behavior
it should download.
You can do
which will give you a 2GB file this will work fine. and it will ask you to save the file as normal but if you do
it is now going to send a 404 error header
Fiber Version
tested the last 4 ones
Code Snippet (optional)
Checklist: