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

Saving TIF Image from the Internet

I have an app that (at the moment) moves through files that are on a web
site, and deletes them, wat i want to do for the next stage, is to be able to
download each file before i delete it.

i have tried POSTin to be able to view the image, then saving it, but it
doesnt work, the problem i have is that all the files on the server have the
same name, which is
http://1.1.1.1/DH/repository/content.tif

and for me to be able to view one, i had to send the follow command (that
has a fwe ids that tell me the server which file i want)

show=&did=31374&rid=6_2_6_1_2_1&sid=17470975690599 0&WidthSize=136&useSavedParam=&dummy=

once i did this i got the followin content response

HTTP/1.1 200 OK
Server: Web-Server/3.0 GW-Repository
Content-Length: 24434
Content-Type: image/x-tiff
Set-Cookie: cookieOnOffChecker=on; path=/
Connection: close

MM

i have tried to use the
WebClient.DownloadData(http://1.1.1.1/DH/repository/content.tif)

but it simply returns an error.

Does enyone have any ideas.
Thanx in advance
Nov 17 '05 #1
5 3099
Thaynann,

What is the error that you are getting? You should be able to set the
query string using the web client as well, and get the correct response, for
you to save.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Thaynann" <Th******@discussions.microsoft.com> wrote in message
news:44**********************************@microsof t.com...
I have an app that (at the moment) moves through files that are on a web
site, and deletes them, wat i want to do for the next stage, is to be able
to
download each file before i delete it.

i have tried POSTin to be able to view the image, then saving it, but it
doesnt work, the problem i have is that all the files on the server have
the
same name, which is
http://1.1.1.1/DH/repository/content.tif

and for me to be able to view one, i had to send the follow command (that
has a fwe ids that tell me the server which file i want)

show=&did=31374&rid=6_2_6_1_2_1&sid=17470975690599 0&WidthSize=136&useSavedParam=&dummy=

once i did this i got the followin content response

HTTP/1.1 200 OK
Server: Web-Server/3.0 GW-Repository
Content-Length: 24434
Content-Type: image/x-tiff
Set-Cookie: cookieOnOffChecker=on; path=/
Connection: close

MM

i have tried to use the
WebClient.DownloadData(http://1.1.1.1/DH/repository/content.tif)

but it simply returns an error.

Does enyone have any ideas.
Thanx in advance

Nov 17 '05 #2
There is no specific message with the exception...just says "Error has
occured in WebClient", i tried grabbing the InnerException, and the
staceTrace, but no actual message with exception, just above.

i have another idea as to how to save it, that is to create a file (probably
with a FileStream) then simply write the response bytes straight to it. im
hopin this will work. ill keep u posted

"Nicholas Paldino [.NET/C# MVP]" wrote:
Thaynann,

What is the error that you are getting? You should be able to set the
query string using the web client as well, and get the correct response, for
you to save.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Thaynann" <Th******@discussions.microsoft.com> wrote in message
news:44**********************************@microsof t.com...
I have an app that (at the moment) moves through files that are on a web
site, and deletes them, wat i want to do for the next stage, is to be able
to
download each file before i delete it.

i have tried POSTin to be able to view the image, then saving it, but it
doesnt work, the problem i have is that all the files on the server have
the
same name, which is
http://1.1.1.1/DH/repository/content.tif

and for me to be able to view one, i had to send the follow command (that
has a fwe ids that tell me the server which file i want)

show=&did=31374&rid=6_2_6_1_2_1&sid=17470975690599 0&WidthSize=136&useSavedParam=&dummy=

once i did this i got the followin content response

HTTP/1.1 200 OK
Server: Web-Server/3.0 GW-Repository
Content-Length: 24434
Content-Type: image/x-tiff
Set-Cookie: cookieOnOffChecker=on; path=/
Connection: close

MM

i have tried to use the
WebClient.DownloadData(http://1.1.1.1/DH/repository/content.tif)

but it simply returns an error.

Does enyone have any ideas.
Thanx in advance


Nov 17 '05 #3
Nicholas,

i have managed to get the image to save, by using the following code

Stream stream = webResponse.GetResponseStream();
Stream imageFile = File.Create(@"C:\IMAGES\image.tif");
Bitmap b = new Bitmap(stream);
b.Save(imageFile, ImageFormat.Tiff);

which works fine, the only problem is that, most of the fils im tryin to
save off teh web page are multi-page Tif files, and using the code above, it
seems to be only saving the first page,

i thought maybe the content returned from the server maybe only for the
first page, but i ran the web page via IE (with Fiddler running) and the
commands are identical to wat i have to view the image and IE lets me move
through the multiple pages of the image,

Any ideas?
Thanx for your help so far.
"Nicholas Paldino [.NET/C# MVP]" wrote:
Thaynann,

What is the error that you are getting? You should be able to set the
query string using the web client as well, and get the correct response, for
you to save.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Thaynann" <Th******@discussions.microsoft.com> wrote in message
news:44**********************************@microsof t.com...
I have an app that (at the moment) moves through files that are on a web
site, and deletes them, wat i want to do for the next stage, is to be able
to
download each file before i delete it.

i have tried POSTin to be able to view the image, then saving it, but it
doesnt work, the problem i have is that all the files on the server have
the
same name, which is
http://1.1.1.1/DH/repository/content.tif

and for me to be able to view one, i had to send the follow command (that
has a fwe ids that tell me the server which file i want)

show=&did=31374&rid=6_2_6_1_2_1&sid=17470975690599 0&WidthSize=136&useSavedParam=&dummy=

once i did this i got the followin content response

HTTP/1.1 200 OK
Server: Web-Server/3.0 GW-Repository
Content-Length: 24434
Content-Type: image/x-tiff
Set-Cookie: cookieOnOffChecker=on; path=/
Connection: close

MM

i have tried to use the
WebClient.DownloadData(http://1.1.1.1/DH/repository/content.tif)

but it simply returns an error.

Does enyone have any ideas.
Thanx in advance


Nov 17 '05 #4
Thaynann wrote:
Nicholas,

i have managed to get the image to save, by using the following code

Stream stream = webResponse.GetResponseStream();
Stream imageFile = File.Create(@"C:\IMAGES\image.tif");
Bitmap b = new Bitmap(stream);
b.Save(imageFile, ImageFormat.Tiff);


You can dump the bytes read from the response stream directly to your
destination file. This can be refactored into a neat helper method.

public void Download(string url, string fileName)
{
// Add error handling for null params and other evil
// stuff on your own ;-)
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse) request.GetResponse();

using (Stream responseStream = response.GetResponseStream())
using (FileStream fileStream =
new FileStream(fileName, FileMode.Create))
{
Copy(responseStream, fileStream);
}
}

public void Copy(Stream source, Stream target)
{
// Add error handling for null params and other evil
// stuff on your own ;-)
byte[] buffer = new byte[0x1000];
int bytes;
try
{
while ((bytes = source.Read(buffer, 0, buffer.Length)) > 0)
{
target.Write(buffer, 0, bytes);
}
}
finally
{
target.Flush();
}
}

Note that there's also Webclient.DownloadFile(), which wraps these
tasks nicey ;-)

cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 17 '05 #5
Thanx for the code, i managed to get it working, with the code u gave me, i
tried to use the webClient.DownloadFile(), but i couldnt, i didnt have diret
access to the URL of the images, as all the Images i was getting had the
exact same URL, the only way to distinguish between each image was via IDs
that the server return when i posted requests.

thanx again for ur input, the app works perfectly, it was deployed yesterday

"Joerg Jooss" wrote:
Thaynann wrote:
Nicholas,

i have managed to get the image to save, by using the following code

Stream stream = webResponse.GetResponseStream();
Stream imageFile = File.Create(@"C:\IMAGES\image.tif");
Bitmap b = new Bitmap(stream);
b.Save(imageFile, ImageFormat.Tiff);


You can dump the bytes read from the response stream directly to your
destination file. This can be refactored into a neat helper method.

public void Download(string url, string fileName)
{
// Add error handling for null params and other evil
// stuff on your own ;-)
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse) request.GetResponse();

using (Stream responseStream = response.GetResponseStream())
using (FileStream fileStream =
new FileStream(fileName, FileMode.Create))
{
Copy(responseStream, fileStream);
}
}

public void Copy(Stream source, Stream target)
{
// Add error handling for null params and other evil
// stuff on your own ;-)
byte[] buffer = new byte[0x1000];
int bytes;
try
{
while ((bytes = source.Read(buffer, 0, buffer.Length)) > 0)
{
target.Write(buffer, 0, bytes);
}
}
finally
{
target.Flush();
}
}

Note that there's also Webclient.DownloadFile(), which wraps these
tasks nicey ;-)

cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de

Nov 17 '05 #6

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

Similar topics

0
by: mchl gdbt | last post by:
Hi, I have several thousand tiffs generated by application A which are read by application B. I need to remove a few colours from the tiffs and I decided to try with the python imaging library....
4
by: Michael Kennedy [UB] | last post by:
Hi Everyone, I have this multithreaded C# windows forms application which does a lot of image processing. Occasionally, I get the following error: A generic error occurred in GDI+....
7
by: Dobedani | last post by:
Dear All, I am developing / maintaining a web application which generates GIF images on the fly. When I send the image, I make sure a header is sent first with MIME-type image/gif. My HTML-code...
4
by: CodeRazor | last post by:
I'm unfamiliar with image manipulation using c#. How can i resize a jpg that currently exists in a file and save it resized as a new file. The examples i've found have been a bit misleading for...
4
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any...
16
by: Fred | last post by:
hi, is there some way to prevent(at least for not so advanced users) image saving on local disk; currently i use javascript which handles the right mouse button click, but all it takes is to...
5
by: TheGanjaMan | last post by:
Hi everyone, I'm trying to write up a simple image stamper application that stamps the Exif date information from the jpegs that I've taken from my digital camera and saves the new file with the...
3
by: Nathan Sokalski | last post by:
I am using ASP.NET, VB.NET, and GDI+ to dynamically create images for webpages. When I right-click on the dynamically created image to try to save it to my hard drive, which I send as...
6
by: Mark Denardo | last post by:
My question is similar to one someone posted a few months back, but I don't see any replies. Basically I want to be able to have users upload photos and save them in a database (as byte data)...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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: 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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.