473,382 Members | 1,651 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,382 software developers and data experts.

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


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.

Nov 14 '05 #1
4 4335
sree <sr**************@gmail.com> 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 ___ Je***********@physik.fu-berlin.de
\__________________________ http://www.toerring.de
Nov 14 '05 #2


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>

--
Er*********@sun.com

Nov 14 '05 #3
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>
Nov 14 '05 #4
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.

Nov 14 '05 #5

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

Similar topics

20
by: Brian Burgess | last post by:
Hi all, Anyone know if this is possible? If so, on which page would the cookie be? .. On the page calling a function defined in the include file? thanks in advance.. -BB
7
by: Dan V. | last post by:
Situation: I have to connect with my Windows 2000 server using VS.NET 2003 and C# and connect to a remote Linux server at another company's office and query their XML file. Their file may be...
16
by: David Lauberts | last post by:
Hi Wonder if someone has some words of wisdom. I have a access 2002 form that contains 2 graph objects that overlay each other and would like to export them as a JPEG to use in a presentation....
0
by: CroDude | last post by:
Hi all! I have problems when writting bitmap to a byte array and after reading it back form byte to Bitmap object. What I do is this: First I throw Bitmap to a memory-stream and then I write it...
19
by: jeremyz | last post by:
Hi all, I am not a developer, but I work with several and am posting this for them. We are trying to determine whether it is possible to check the size of a file before a user uploads it. ...
4
by: Pacino | last post by:
Hi, everyone, I am wondering whether it's possible to read part (e.g. 1000*1000) of a huge jpeg file (e.g. 30000*30000) and save it to another jpeg file by pure python. I failed to read the...
11
by: Mark B | last post by:
I want to display a pre-designed graphical 'performance badge' on certain webpages (round, about 2cm diameter) next to a salesperson's details. I have a function,...
2
by: soni2926 | last post by:
Hi, I wanted to make a page where I can send a request to another page, and read it's response back, can someone point me to an example? it's just a basic page i need to hit, i can hit it directly...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.