ex04

command
v0.0.0-...-c93e153 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2018 License: MIT Imports: 5 Imported by: 0

README

Q3.4 : zipファイルをウェブサーバからダウンロード

zipファイルの出力先は単なるio.Writerです。そのため、2.4.4「インターネットアクセスの送信」で紹介したウェブサーバーで、zipファイルを作成して そのままダウンロードさせるといったことも可能です。ウェブサーバーにブラウザでアクセスしたらファイルがzipダウンロードされるようにしてみましょう。
この場合は、次のようにContent-Typeヘッダーを使ってファイルの種類がzipファイルであることをブラウザに教えてあげる必要があります。必須ではありませんが、 ファイル名も指定できます。

func handler(w http.ResponseWriter, r *http.Request) {
    w.Header().Set("Content-Type", "application/zip")
    w.Header().Set("Content-Disposition", "attachment;filename=ascii_sample.zip")
}

Result

$ unzip ~/Desktop/ascii_sample.zip
Archive:  /Users/shimizu-yoichiro/Desktop/ascii_sample.zip
  inflating: test
$ ls
README.md    test         zipserver.go
$ cat test
content of file in zip%

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL