Skip to content

How to download a file? #92

Closed Answered by mymmrac
knightpp asked this question in Q&A
Apr 6, 2023 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

It's actually written in comment of this func, The file can then be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>, where <file_path> is taken from the response..

So you would download it from URL using something like this:

DownloadFile("some.file", "https://api.telegram.org/file/bot<token>/<file_path>")

// ...

func DownloadFile(filepath string, url string) error {
	// Get the data
	resp, err := http.Get(url)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	// Create the file
	out, err := os.Create(filepath)
	if err != nil {
		return err
	}
	defer out.Close()

	// Write the body to file
	_, err = io.Copy(out, resp.Body)
	return err
}

Source: htt…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@knightpp
Comment options

@mymmrac
Comment options

@mymmrac
Comment options

Answer selected by knightpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants