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

Saving Stream as Image File

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 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())
StoreRequestStream.Write(RequestData)

'Close the StreamWriter Object
StoreRequestStream.Close()
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))

Try
objDestFile = New FileStream("D:/ImageTest/Test.jpg",
FileMode.Create, FileAccess.Write)
BinWriter = New BinaryWriter(objDestFile)
BinWriter.Write(ImgByteArr)
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.

Regards,

Umesh.
Jul 21 '05 #1
0 1625

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

Similar topics

3
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...
2
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...
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...
5
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...
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...
2
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...
0
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...
0
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...
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: 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...
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
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...
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
agi2029
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,...
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.