Serving a file through HTTP

Jp Calderone exarkun at intarweb.us
Tue Mar 18 18:33:20 CET 2003


On Tue, Mar 18, 2003 at 03:21:52PM +0100, Gerhard H?ring wrote:
> [snip]
>     def do_GET(self):
>         """Serve a GET request."""
>         self.send_header("Content-Type", "audio/mp3")
>         self.end_headers()
> 
>         my_mp3_file = open("Metallica - Nothing Else Matters.mp3", "rb")
> 
>         # Reading the entire file at once is probably not that great a
>         # strategy.
>         self.wfile.write(my_mp3_file.read())

  A cheap improvement on the above line is shutil.copyfileobj()

  Jp

-- 
Where a calculator on the ENIAC is equipped with 18,000 vacuum tubes and
weighs 30 tons, computers in the future may have only 1,000 vacuum tubes and
weigh only 1.5 tons.    -- Popular Mechanics, March 1949
-- 
 up 15 days, 10:00, 2 users, load average: 0.00, 0.00, 0.00





More information about the Python-list mailing list