[thelist] ASP file upload problems

Wade Armstrong wade_lists at runstrong.com
Sat Apr 20 20:12:01 CDT 2002


on 4/20/02 1:30 PM, Amy Johnson at ajohnson at purplemountain.net wrote:

>
>
>> From: Wade Armstrong <wade_lists at runstrong.com>
>
>>> on 4/19/02 11:08 AM, Amy Johnson at ajohnson at purplemountain.net wrote:
>
>>> Hi.  I am trying to set up a web site where the client can log in and upload
>>> web images to the server.  I am using the
>>> ASPSimpleUpload component.  My problem is security.  First we tried putting
>>> the writeable directory in an area outside the web
>>> space.  This worked great for uploading and deleting the files.  BUT the web
>>> page could not access the images.
>
>> The HTML you write out indeed can't access the image. But ASP can, since it
>> runs under a different security context! Instead of <img
>> src="uploads/picture.jpg"> try <img src="image.asp?image=picture.jpg">. The
>> image.asp script then would open the image specified in the querystring, set
>> the correct content-type, and output the image (actually, a straight
>> Server.Transfer of the proper image might do the entire job in one line of
>> code).
>
>> Wade
>
> Wade, thanks for the suggestion!  My ASP book gives some sample code for
> something like this but it says I need to get a
> "third-party control" that will allow me to open a binary file.  They use
> ObjBin.ReadFile in their sample code.  Any idea where I
> could get such a control?
>

I don't think you need a control for this.

The 4 Guys from Rolla have an article on this:
http://www.4guysfromrolla.com/webtech/083100-1.shtml

which suggests this code:
'Create a stream object
  Dim objStream
  Set objStream = Server.CreateObject("ADODB.Stream")

  'Open a GIF file
  objStream.Type = adTypeBinary
  objStream.Open
  objStream.LoadFromFile Server.MapPath("/images/banner/dimacbanner1.gif")

  'Output the contents of the stream object
  Response.ContentType = "image/gif"
  Response.BinaryWrite objStream.Read

  'Clean up....
  objStream.Close
  Set objStream = Nothing

Should work perfect for you.

You could also use the FileSystemObject's ReadFile method for this, I'm
pretty sure. It's been a while since I've done something like this.

You could also try the following code if you're running IIS 5:
Response.ContentType = "image/gif"
Server.Transfer(Request.Querystring("image"))


Wade




More information about the thelist mailing list