pupcloud icon indicating copy to clipboard operation
pupcloud copied to clipboard

Demo site: browser doesn't always download files when clicking the download button

Open clb92 opened this issue 2 years ago • 6 comments

I believe it's because you're sending the header Content-Disposition: inline, where it should probably be Content-Disposition: attachment if you click the download button, so the browser doesn't just show the file in the browser.

I did a quick test, and that seems to fix it.

clb92 avatar May 08 '22 17:05 clb92

Hmmm.. I think I am doing just this. Did you try in the demo UI or in the app itself? I tested it for a minute, it works (in the app, with firefox at least), and while the web developer tool doesn't show the download request for some reasons (why??), a file (and even an html file) gets downloaded just fine. Mistery.

proofrock avatar May 08 '22 18:05 proofrock

handlers.go:108

	c.Set("Content-Type", item.MimeType)
	c.Set("Content-Length", fmt.Sprintf("%d", item.Size))
	if forDownload {
		c.Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", filepath.Base(fullPath)))
	} else {
		c.Set("Content-Disposition", fmt.Sprintf("inline; filename=\"%s\"", filepath.Base(fullPath)))
	}

Note to myself, this is the piece of code in version 0.8.0

proofrock avatar May 08 '22 18:05 proofrock

Did you try in the demo UI or in the app itself?

I tested it on your demo site, using Burp Suite proxy to modify the response as it came back to my browser.

the web developer tool doesn't show the download request for some reasons (why??)

Yeah I noticed that too, also in Firefox. I'm not into debugging weird web app frontend shenanigans, so I decided not to poke that bear, and fired up Burp instead.

clb92 avatar May 08 '22 18:05 clb92

Aaaah ok. I'm afraid the demo site just uses mockup services, so I can't set any header... the "proper" app actually works. I could move the site to a serverless backend setup, it would be interesting, also for unifying the codebase... I'll think about it, but it's low priority for now. Maybe. It's interesting, so I could just do it.

Would you mind if I leave this open and modify the title to "Demo site: Browser doesn't always..."?

proofrock avatar May 08 '22 18:05 proofrock

Would you mind if I leave this open and modify the title to "Demo site: Browser doesn't always..."?

You do whatever helps you keep track of it best :-)

clb92 avatar May 08 '22 18:05 clb92

Thanks for your time! And I didn't know Burp Suite, I definitely need it if it can act as a proxy like you used it.

proofrock avatar May 08 '22 18:05 proofrock