Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there way to download file with prompting name ? #1243

Closed
shawnye opened this issue Feb 4, 2018 · 2 comments
Closed

Is there way to download file with prompting name ? #1243

shawnye opened this issue Feb 4, 2018 · 2 comments

Comments

@shawnye
Copy link

shawnye commented Feb 4, 2018

I try c.File(fileName) , it does not provide prompting name when downloading, could you provide api such as c.File(fileName, promptName string) ?

As echo does:

// Attachment sends a response as attachment, prompting client to save the file.
Attachment(file string, promptName string) error

Thank you!

@shawnye
Copy link
Author

shawnye commented Feb 4, 2018

my workaround:

downloadName := "test"+time.Now().Format("20060102150405") + ".csv"

	header := c.Writer.Header()
	header["Content-type"] = []string{"application/octet-stream"}
	header["Content-Disposition"] = []string{"attachment; filename= " + downloadName}

	file, err := os.Open(destFile)
	if err != nil {
		c.String(http.StatusOK, "%v", err)
		return
	}
	defer file.Close()

	io.Copy(c.Writer, file)

@thinkerou
Copy link
Member

@shawnye please see #1304 use c.DataFromReader

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants