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

Saving Stream as Image.

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 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.

Nov 21 '05 #1
0 1121

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

Similar topics

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...
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...
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)...
2
by: keerthisreenu | last post by:
hai to all...!! iam working with Ms Access 2000. iam saving an image in the database. After that i want to retrive the same image from database and displaying it in the picture box. but its not...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.