Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > how can i read a jpeg file using c and send back to the browser which is requesting

Reply
Thread Tools

how can i read a jpeg file using c and send back to the browser which is requesting

 
 
sree
Guest
Posts: n/a
 
      03-10-2005

i am doing project a simple http server. it is being writen in
c using sockets. so when there is a request to read a jpeg or any other
file icant do it. my code is working only for html and txt fils. Is
there seperate way to open jpegs etc and buffer them and send them.

 
Reply With Quote
 
 
 
 
Jens.Toerring@physik.fu-berlin.de
Guest
Posts: n/a
 
      03-10-2005
sree <(E-Mail Removed)> wrote:
> i am doing project a simple http server. it is being writen in
> c using sockets. so when there is a request to read a jpeg or any other
> file icant do it. my code is working only for html and txt fils. Is
> there seperate way to open jpegs etc and buffer them and send them.


In principle there should be no problem in opening, reading or
writing jpeg (or other non-text) files. The only thing you may
have to be careful about is to open the file in binary mode in-
stead of the default text mode, e.g. to open the file for rea-
ding use

FILE *fp = fopen( "myfile.jpeg", "rb" );

since otherwise on some platforms "\r\n" combinations might not
get read in in the way you need it.

And, of course using text oriented functions like fscanf() or
fprintf() etc. doesn't make sense with these files, use fread()
and fwrite(). If that shouldn't help you solve your problem you
should post the relevant part of your code since it otherwise
is impossible to guess what might be going wrong. But keep out
stuff about sockets since that is too much dependent on the
platform you're using and not part of the C language, so you
better ask about that in a newsgroup that is for discussions
about programming on your platform.

Regards, Jens
--
\ Jens Thoms Toerring ___ http://www.velocityreviews.com/forums/(E-Mail Removed)-berlin.de
\__________________________ http://www.toerring.de
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      03-10-2005


sree wrote:
> i am doing project a simple http server. it is being writen in
> c using sockets. so when there is a request to read a jpeg or any other
> file icant do it. my code is working only for html and txt fils. Is
> there seperate way to open jpegs etc and buffer them and send them.


<divination>

You have an error at line 362.

<guess>

Open the JPEG file with "rb" mode instead of just "r".

</guess>

</divination>

--
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
T Koster
Guest
Posts: n/a
 
      03-12-2005
sree wrote:
> i am doing project a simple http server. it is being writen in
> c using sockets. so when there is a request to read a jpeg or any other
> file icant do it. my code is working only for html and txt fils. Is
> there seperate way to open jpegs etc and buffer them and send them.
>


Jens and Eric have already given you likely C-related answers, but since
you haven't told us exactly what is broken, there are other (off-topic)
possibilities:

<OT>
When you say your code is "working" only for html and txt files, do you
mean that jpeg files are not sent across the to the client at all? Or
do you get unexpected output? If you expect a to see a picture showing
up in your browser but instead you get seemingly garbled nonsensical
text, the problem may not be in your file I/O but with your handling of
the HTTP protocol, such as not sending the correct Content-Type headers
for example.
</OT>
 
Reply With Quote
 
sree
Guest
Posts: n/a
 
      03-13-2005
thanks to jens, Eric and Koster for helping me.

The mistake i did is for jpeg files to send we have to send the http
respond header Content-type settin it as image/jpeg. which i did not
do.
it is not mistake in c code but sending the header.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to read from a file, stored the data in an array, and return number of records read back to main tyeung168@gmail.com C++ 2 02-27-2007 07:12 AM
how to know the server the browser is requesting pages from thecoolone Computer Support 1 12-10-2006 06:22 PM
Nikon D70 RAW converted to JPEG - jpeg file size 3MB ? 5 MB? Amit Digital Photography 3 03-17-2006 10:40 AM
How can I send back(Post back) some values from client machine Joby ASP .Net 0 05-14-2004 04:19 AM



Advertisments