writing image to disk

A

aarondouglas28

Hey all,
I'm hoping someone can help me with a little problem I have.
First a little background. I'm working on developing a site which
displays live feeds from a security camera. The camera is connected to
our network via a network video server. Now here's the problem.
One of the requirements of this particular project is that the user be
able to save a snapshot of the live video feed at any given time and
save it to disk. Now, the network video server provides a method for
generating snapshots. The problem I have is getting the page to save
the snapshot automatically.

The address of the image actually works out to be something like
"http://www.site.com:97/images1sif?random=4325623"

The port is specified in the address because that is how the network
camera server is referenced by our routers.

I currently have a page set up that can display an image specified and
has a save button that the user can click to save the image (some of
our users aren't bright enough to right click and choose save as...).
The code I currently have is as follows:

sFileName = "Temp.jpg"
sFile = imgArchive.ImageUrl
Response.ClearHeaders()
Response.ClearContent()
Response.Clear()
Response.AddHeader("Content-Disposition","attachment;filename=" &
sFileName)
Response.ContentType = "Image/JPG"
Response.WriteFile(Server.MapPath(sFile))

This code works fine when the image is stored on the server itself,
however the images I need to save are not stored on the server, they
are on the network video server as I stated before.

Also, I will need to occasionally save these images directly to our
server for other purposes.

Any help that can be provided is appreciated. If any other
clarification is needed, please let me know.
 
S

Steve C. Orr [MVP, MCSD]

First you need to retrieve the image file from the video server before you
can use Response.Writefile (or a similar function) or save it to the server.
This can be done in .NET 1.x with the WebRequest object.
Here's more info on the WebRequest object.
http://msdn.microsoft.com/library/d...f/html/frlrfsystemnetwebrequestclasstopic.asp

In VB2005 its even easier. It can be done with a single line of code:
My.Computer.Network.DownloadFile(address as string, destinationFileName as
string)
 
A

aarondouglas28

Thank you very much Steve. I will try this first thing in the morning
when I get back to the office.
 
A

aarondouglas28

Steve,
Thanks again for the quick response. I do have a further question
though, and please bear in mind that I am brand new to asp.net.
While searching for solutions based off your suggestion, I came upon
the following code:


Sub Page_Load(Sender As Object, E As EventArgs)
Dim sURL As String = "http://www.site.com:82/images1sif?random=12345
Dim SR2 = New
StreamReader(System.Net.WebRequest.Create(sURL).GetResponse().GetResponseStream(),System.Text.Encoding.Unicode,True,1000000)
System.Drawing.Image.FromStream(SR2.BaseStream).Save(Server.MapPath("../../Output/testing.gif"),System.Drawing.Imaging.ImageFormat.GIF)
End Sub

Now, this code works perfectly fine if the image is in a directory on
our server (i.e. www.site.com/images/image.jpg) but it fails when I try
and specify our video server which is referenced by going to port 82.

When I try and do this I get the error "The underlying connection was
closed: Unable to connect to the remote server."

Is this a problem relating to the fact that I'm specifying a port
number? Or could it possibly be that the video server just isn't
responding to the request? Keep in mind that if I just go to
www.site.com:82?/images1sif?random=12345 the image comes up perfectly
fine.

Is there another way to go about what I'm trying to do? Possibly load
the image into a standard html <img> tag and then somehow save the
contents to disk?
Again, I'm new to asp.net so please forgive me if I'm missing something
obvious.

Thanks again
Aaron Douglas
 
S

Steve C. Orr [MVP, MCSD]

By default the ASPNET user account does not have access to network
directories. Either grant it access or have ASP.NET run under a different
user account by using impersonation.

For example, you can add a line similar to this to your web.config file:
<identity impersonate="true" userName="domain\MyAppUser">
password="password"/>

For testing purposes you can have it use your user account since you know
you have the necessary permissions to write to that network location.

Here's more info on impersonation:
http://msdn.microsoft.com/library/d...-us/cpguide/html/cpconaspnetimpersonation.asp
 
A

aarondouglas28

I'm sorry, there's one thing I didn't necessarily make clear. The
network video server in this case is not actually another computer. It
is simply a stand alone device that is connected to the network, and
the security camera at the same time. This is a box that has very
limited capabilities. The only software it really has running on it is
a basic web server (I'm not even sure what kind) and whatever software
is needed to control the camera. There are no logins, or users to
really speak of.

Is there possibly another way to do this? As I stated, loading the
image into a image control works perfectly fine. Is there any way to
possibly user the system.drawing namespace to somehow save the image?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top