473,396 Members | 2,076 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,396 software developers and data experts.

Saving Stream as Image File


I have an Application, in which
1) need to post data to a URL(Remote Server), by using HTTPRequest.
2) get the Image data in the form of Stream in Response.
3) need to save this stream as a Image file on the local machine.

Giving some code snippet below.

RequestAPI = CType(WebRequest.Create(URLName), HttpWebRequest)
RequestData = ImageName
RequestAPI.ContentType = "application/x-www-form-urlencoded"
RequestAPI.Method = "POST"
StoreRequestStream = New StreamWriter(RequestAPI.GetRequestStream())

'Close the StreamWriter Object
StoreResponse = CType(RequestAPI.GetResponse(), HttpWebResponse)
Dim ImgStream As Stream
Dim StremaLen As Long

ImgStream = StoreResponse.GetResponseStream()
StremaLen = StoreResponse.ContentLength
'**** For Saving Image File ****
WriteImgFile(ImgStream, StremaLen)

Public Sub WriteImgFile(ByVal ImgStream As Stream, ByVal RespLen As Long)
Dim BinReader As BinaryReader
BinReader = New BinaryReader(ImgStream)

Dim BinWriter As BinaryWriter
Dim objDestFile As FileStream
Dim ImgByteArr() As Byte

ImgByteArr = BinReader.ReadBytes(CInt(RespLen))

objDestFile = New FileStream("D:/ImageTest/Test.jpg",
FileMode.Create, FileAccess.Write)
BinWriter = New BinaryWriter(objDestFile)
Catch ex As IOException
End Try
End Sub

The problem is, I get StoreResponse.ContentLength as -1, which prevents me
from saving the Stream data as File. Actually Image resides on the server.
How this can be achieved ?

Any help in this regard would be appreciated.

Thanking you in anticipation.


Jul 21 '05 #1
0 1624

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

Similar topics

by: cdj | last post by:
Hi all, I've got a picturebox on a form, and a save button. When I go to save, the app craps out with the following error: ================== An unhandled exception of type...
by: Peder Y | last post by:
Say I have several images, a jpg a gif and a bmp. Now, I want to save these files to a single binary file. I store the images in, say, Image img1, img2, img3; 1) How can I retrieve the size...
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...
by: Thaynann | last post by:
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...
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...
by: asad | last post by:
Hello friends, how ru all, i have some problem about saving created thumbnail, following is the code i use for creating thumbnail but thumbnail was not saved it is on memory which method is used to...
by: Umesh | last post by:
Hi Gurus, I have an Application, in which 1) need to post data to a URL(Remote Server), by using HTTPRequest. 2) get the Image data in the form of Stream in Response. 3) need to save this...
by: Umesh | last post by:
Hi, I have an Application, in which 1) need to post data to a URL(Remote Server), by using HTTPRequest. 2) get the Image data in the form of Stream in Response. 3) need to save this stream as a...
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)...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
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: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.