Notices

Great community. Great ideas.

Welcome to ASP/Free, a community dedicated to helping beginners and professionals alike in improving their knowledge of Microsoft's development and administration technologies. Sign up today to gain access to the combined insight of tens of thousands of members.

Thread: Response.BinaryWrite

Page 2 of 2 FirstFirst 12
Results 16 to 25 of 25
Share This Thread →
  1. #16
    selwonk's Avatar
    selwonk is offline Contributing User
    Join Date
    Jun 2004
    Posts
    3,072
    Rep Power
    189
    Incidentally, get rid of using WriteBlobToFile(...) as this appears to create a disk file image which is exactly what you are trying to avoid!
    http://www.MapDays.com | Find events wherever, whenever you want them


  2. #17
    Belord is offline Contributing User
    Join Date
    Dec 2004
    Posts
    329
    Rep Power
    10

    Image Issue

    Mike,

    Can you send me the code as an sample if you dont mind


    Your help is greatly appreciated.

    thanks,

    Belord

  3. #18
    selwonk's Avatar
    selwonk is offline Contributing User
    Join Date
    Jun 2004
    Posts
    3,072
    Rep Power
    189
    Ok - when I get to the office I'll fish one out for you and simplify it a bit. You're on the right track - I think you need to take a step back and look at it from a simpler angle.I'll get back in the morning...

  4. #19
    selwonk's Avatar
    selwonk is offline Contributing User
    Join Date
    Jun 2004
    Posts
    3,072
    Rep Power
    189
    By the way - what DB are you using?

  5. #20
    Belord is offline Contributing User
    Join Date
    Dec 2004
    Posts
    329
    Rep Power
    10

    Image

    hi,

    I am using Sql server 2000

    Belord

  6. #21
    selwonk's Avatar
    selwonk is offline Contributing User
    Join Date
    Jun 2004
    Posts
    3,072
    Rep Power
    189
    Perfect. The example I have in mind is for MySQL (no s******ing please - it's for a cheapo development). It uses a variety of techniques to display the image. It could be quite useful for you. I can't remember what upload component it uses, but it stores the image dimensions in the upload routine for use later and can return either an image, a disk clip file, or statistics about an image. I'll see whether I have a copy on USB...

  7. #22
    selwonk's Avatar
    selwonk is offline Contributing User
    Join Date
    Jun 2004
    Posts
    3,072
    Rep Power
    189
    Nope - it's on my office workstation. Manana!

  8. #23
    selwonk's Avatar
    selwonk is offline Contributing User
    Join Date
    Jun 2004
    Posts
    3,072
    Rep Power
    189
    Ok - I was using Persists to handle the file upload. I presume that this part is working for you if you already have image data in the DB. The following code is used to display the image. It accepts a few parameters including the ability to read the dimensions of the image which is saved during the Persists upload:
    Code:
    <!-- #include file="params.inc.asp" -->
    <!-- #include file="lib.inc.asp" -->
    <!-- #include file="open.db.inc.asp" -->
    <%
     ' On Error Resume Next
     str_Mode = Request.QueryString("Mode")
     str_SQL1 = "SELECT Image#ImageNumber# AS Image, Image#ImageNumber#Width AS Width, Image#ImageNumber#Height AS Height, Image#ImageNumber#Name AS Name, Image#ImageNumber#Size AS Size FROM Tributes WHERE GUID='#GUID#' AND Image#ImageNumber#Size<>0"
     str_SQL2 = "SELECT Clip#ImageNumber# AS Image FROM Tributes WHERE GUID='#GUID#'"
     str_SQL1 = Replace(str_SQL1, "#ImageNumber#", Request.QueryString("ImageNumber"))
     str_SQL2 = Replace(str_SQL2, "#ImageNumber#", Request.QueryString("ImageNumber"))
     str_SQL1 = Replace(str_SQL1, "#GUID#", Request.QueryString("GUID"))
     str_SQL2 = Replace(str_SQL2, "#GUID#", Request.QueryString("GUID"))
     Set obj_RecordSet2 = obj_Connection.Execute(str_SQL1, adBoolean)
     Set obj_RecordSet3 = obj_Connection.Execute(str_SQL2, adBoolean)
     If obj_RecordSet3("Image") <> "" Then 
      Select Case str_Mode
       Case "SHOW"
    	str_Mode = "SHOWCLIP"
       Case "SHOWLIVE"
    	str_Mode = "SHOWCLIPLIVE"
       Case "REPORT"
    	str_mode = "REPORTCLIP"
      End Select
     End If
     Select Case str_Mode
      Case "SHOWCLIP"
       Set obj_HTTP = Server.CreateObject("Microsoft.XMLHTTP.1.0")
       ' obj_HTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
       obj_HTTP.Open "GET", "http://www.yourtribute.co.uk/" & obj_RecordSet3("Image"), False
       obj_HTTP.Send
       Response.ContentType = "image/gif"
       Response.BinaryWrite(obj_HTTP.ResponseBody)
       Set obj_HTTP = Nothing
      Case "SHOWCLIPLIVE"
       Set obj_HTTP = Server.CreateObject("Microsoft.XMLHTTP.1.0")
       ' obj_HTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
       obj_HTTP.Open "GET", "http://www.yourtribute.co.uk/" & obj_RecordSet3("Image"), False
       obj_HTTP.Send
       Response.ContentType = "image/gif"
       Response.BinaryWrite(obj_HTTP.ResponseBody)
       Set obj_HTTP = Nothing
      Case "SHOW"
       If NOT obj_RecordSet2.EOF Then
    	Response.ContentType = "image/gif"
    	Response.BinaryWrite(obj_RecordSet2("Image"))
       Else
    	Set obj_HTTP = Server.CreateObject("Microsoft.XMLHTTP.1.0")
    	' obj_HTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    	obj_HTTP.Open "GET", "http://www.yourtribute.co.uk/images/empty.gif", False
    	obj_HTTP.Send
    	Response.ContentType = "image/gif"
    	Response.BinaryWrite(obj_HTTP.ResponseBody)
    	Set obj_HTTP = Nothing
       End If
      Case "SHOWLIVE"
       If NOT obj_RecordSet2.EOF Then
    	Response.ContentType = "image/gif"
    	Response.BinaryWrite(obj_RecordSet2("Image"))
       Else
    	Set obj_HTTP = Server.CreateObject("Microsoft.XMLHTTP.1.0")
    	' obj_HTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    	obj_HTTP.Open "GET", "http://www.yourtribute.co.uk/images/spacer.gif", False
    	obj_HTTP.Send
    	Response.ContentType = "image/gif"
    	Response.BinaryWrite(obj_HTTP.ResponseBody)
    	Set obj_HTTP = Nothing
       End If
      Case "NAME"
       If NOT obj_RecordSet2.EOF Then
    	Response.Write(obj_RecordSet2("Name"))
       End If
      Case "REPORTCLIP"
       ary_Image = Split(obj_RecordSet3("Image"),"/")
       Response.Write("Clipart - " & ary_Image(2) & "<p>")
       Response.Write("<b>Click <a href=""3.asp?RemoveClip=" & Request.QueryString("ImageNumber") & """>here</a> to remove<br>this clipart</b>")
      Case "REPORT"
       If NOT obj_RecordSet2.EOF Then
    	Response.Write("Filename - " & obj_RecordSet2("Name") & "<br>")
    	Response.Write("Size - " & obj_RecordSet2("Size") & " bytes<br>")
    	Response.Write("Dimensions - " & obj_RecordSet2("Width") & " x " & obj_RecordSet2("Height") & " pixels<p>")
    	Response.Write("<b>Click <a href=""3.asp?RemoveImage=" & Request.QueryString("ImageNumber") & """>here</a> to remove<br>this image</b>")
       Else
    	Response.Write("No image uploaded<p>A sample image has been displayed")
       End If
     End Select
    %>
    <!-- #include file="close.db.inc.asp" -->

  9. #24
    selwonk's Avatar
    selwonk is offline Contributing User
    Join Date
    Jun 2004
    Posts
    3,072
    Rep Power
    189
    This is the upload script which handles storing the image and dimensions in the DB:
    Code:
    <!-- #include file="params.inc.asp" -->
    <!-- #include file="lib.inc.asp" -->
    <!-- #include file="open.db.inc.asp" -->
    <html>
    <head>
    <title>YourTribute.co.uk /// Special tributes for special people</title>
    <script language="JavaScript" src="head.js"></script>
    <link rel="stylesheet" href="css/styles.css" type="text/css">
    </head>
    <body bgcolor="#cccccc">
    <!-- #include file="top.html" -->
    				  <p> 
    					<!-- hashinclude file="engine.asp" -->
    					<img src="steps/3.gif" width="600" height="80" vspace="5" alt="[Step 1 - Enter the recipient details] [Step 2 - Enter the tribute text] [Step 3 - Add some images or photos] [Step 4 - Finalise the format of your tribute] [Step 5 - Purchase your tribute]"><br>
    				  <p><b><img src="graphics/photo.gif" width="135" height="123" align="right" alt="Photograph">Uploading 
    					files...</b></p>
    <%
     Set Upload = Server.CreateObject("Persits.Upload") 
     ' we use memory uploads, so we must limit file size
     Upload.SetMaxSize 100000, True
     ' Save to memory. Path parameter is omitted
     Count = Upload.Save
     ' Save GUID
     str_GUID = Session("GUID")
     ' Obtain file object
     int_UploadCounter = 0
     For int_Counter = 1 TO 3
      Set File = Upload.Files("Image" & int_Counter)
      If Not File Is Nothing Then
       ' Check the file
       int_Errors = 0
       If File.Size > 50000 Then
    	Response.Write("Image " & int_Counter & " is too large. Images should be less than 500KB<p>")
    	int_Errors = 1
       End If
       If File.ImageType = "UNKNOWN" Then
    	Response.Write("Image " & int_Counter & " is not supported. The image should end with one of these extensions: BMP, GIF, JPG or PNG<p>") 
    	int_Errors = 1
       End If
       If File.ImageWidth > 200 OR File.ImageHeight > 250 Then
    	Response.Write("Image " & int_Counter & " is too large. The image should be no larger than 200 by 250 pixels. Your image is " & File.ImageWidth & " pixels wide and " & File.ImageHeight & " tall<p>")
    	int_Errors = 1
       End If
       If int_Errors = 0 Then
    	str_Connection = CONNSTRING
    	str_SQL = "UPDATE Tributes SET Image" & int_Counter & "=?, Image" & int_Counter & "Width=" & File.ImageWidth & ",Image" & int_Counter & "Size=" & File.Size & ", Image" & int_Counter & "Height=" & File.ImageHeight & ", Image" & int_Counter & "Name='" & File.FileName & "' WHERE GUID='" & str_GUID & "'"
    	File.ToDatabase str_Connection, str_SQL
    	int_UploadCounter = int_UploadCounter + 1
       End If
      End If
     Next
     If int_UploadCounter <> 0 Then
      Response.Write(int_UploadCounter & " image(s) have been uploaded. Click <a href=""3.asp"">here</a> to continue")
     Else
      Response.Write("<font color=""red"">You did not choose any files to upload, or there was a problem with the images you attempted to upload. Click <a href=""3.asp"">here</a> to try again</font>")
     End If
    %>
    <!-- #include file="bot.html" -->
    </body>
    </html>
    <!-- #include file="close.db.inc.asp" -->

  10. #25
    Belord is offline Contributing User
    Join Date
    Dec 2004
    Posts
    329
    Rep Power
    10

    Image

    Hi,

    I am getting pretty confused with your code can you do a favour on me and just cut the code and sent me the code where i have to display the images

    Your help is greatly appreciated
    thanks
    belord

Page 2 of 2 FirstFirst 12
Share This Thread →

Become Part of This Conversation

Join NowFor Free!

Similar Threads

  1. response.binarywrite cuts some of the image
    By Tomasz Ptak in forum ASP Development
    Replies: 0
    Last Post: August 11th, 2004, 03:36 AM
  2. Response.BinaryWrite doesn't write files > 64 kb
    By kavithapatil in forum ASP Development
    Replies: 3
    Last Post: June 22nd, 2004, 01:24 AM
  3. Response.ContentType = "application/pdf" Issue
    By antodomnic in forum ASP Development
    Replies: 5
    Last Post: January 26th, 2004, 02:48 AM
  4. Save name of BLOB after a response.binarywrite
    By Steve Schofield in forum ASP Development
    Replies: 1
    Last Post: October 17th, 2001, 07:14 AM

ASP Free Advertisers and Affiliates