473,400 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

Serving binary content (images, etc) using BasteHTTPServer

I'm writing a simple web server in python using the BaseHTTPServer
library. I can serve text content (ie html pages) with ease, but im
running into troubles when i try to serve images. The image gets
corrupted in transit and when I manually download the image from the
website and look at it using a hex editor it appears that the first 60
(or first 3C in hex if it makes a helps) characters are missing.
My code looks like this:

def do_GET(s):

# code that determines that yes this is an image

s.send_response(200)
s.send_header("Content-type", "image/jpeg")
s.end_headers

fileObj = open("1.jpg","rb") # file is harcoded until
i get images being served correctly
image = fileObj.read()
s.wfile.write(image)
Jun 27 '08 #1
2 2843
Ma*****@gmail.com wrote:
I'm writing a simple web server in python using the BaseHTTPServer
library. I can serve text content (ie html pages) with ease, but im
running into troubles when i try to serve images. The image gets
corrupted in transit and when I manually download the image from the
website and look at it using a hex editor it appears that the first 60
(or first 3C in hex if it makes a helps) characters are missing.
My code looks like this:

def do_GET(s):

# code that determines that yes this is an image

s.send_response(200)
s.send_header("Content-type", "image/jpeg")
s.end_headers

fileObj = open("1.jpg","rb") # file is harcoded until
i get images being served correctly
image = fileObj.read()
s.wfile.write(image)
Don't you miss a Content-Length header?

Diez
Jun 27 '08 #2

<Ma*****@gmail.comwrote in message news:556871d3-1fea-40f2-9cc6-
s.end_headers
A bare method name (without parentheses) won't get called.
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Eric Ellsworth | last post by:
Hi, I've been wrestling for several months now with this issue in IE: http://support.microsoft.com/?kbid=308090 (IE thinks that ZIPs sent from a script are corrupt when they are not). IE now...
13
by: Margaret MacDonald | last post by:
I want to store frequently-used graphic elements in a db and serve them from there rather than from the filesystem. Is there a better/faster way to do that than this? (error checking etc not...
5
by: Blaktyger | last post by:
How can this be done? Images are stored in a LONGBLOB field. When I try to display them, it prints out the binary data as it is... Thank you
2
by: Thomas W | last post by:
Hi, I'm having some problems serving binary data in a simple CGI-script. I'm setting content-type ( "application/octet-stream" ), content-length and Content-disposition and I think these are...
3
by: Josema | last post by:
Hi to all, I have stored in a database some binary files (pdfs, and gif images), i would like to know how could i show it, in internet explorer when a person enters for instance in a textbox the...
3
by: Arun | last post by:
Hi, I have simple question to ask. How to write multiple Binary files to the Browser using Asp.Net and Visual C#.net I have seen examples where single binary file is written to browser. ...
3
by: CLEAR-RCIC | last post by:
I have several images i want to display in an ASP.Net application. The images are being passed to me in binary format from another application. Is there a good way to write them directly to an...
13
by: greg | last post by:
Hello, I'm searching to know if a local file is ascii or binary. I couldn't find it in the manual, is there a way to know that ? thanks, -- greg
4
by: =?Utf-8?B?SmFtZXMgUGFnZQ==?= | last post by:
Hi all I have a SQL database where images are stored in a varBinary field. I can display those images within a image control on a page by using the following: ImageUrl='<%# Eval("PictureID",...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.