Quote:
Originally Posted by captainB
Frinavale - Thank you for such a detailed response!
Let me see if I am implementing your suggestion correctly:
I have a gallery page with thumbnails, and each thumbnail is a link to a page - download.aspx - which shows the select thumbnail and a simple form with name, city, state and comments fields. The form's submit button uses POST to send the form back to the server - the url it uses is download.aspx.cs, which has methods to save the fields to a sql server database.
I wasn't quite suggesting this.
I was suggesting creating an ASPX page that would not return HTML...instead it would return a "thumbnail" version of the image.
This "ASPX" page would be called something like "Thumbnail.aspx" and would return a very low resolution image of the original image.
This page would have a Response.ContentType="image/jpg". It would read the image into memory and write a low resolution version of the image directly to the output stream.
For example, the following ASPX page will read return an low-resolution thumbnail image when called.
-
Private _imagePath As String = "~/images/"
-
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
-
'Changing the page's content type to display images
-
Response.ContentType = "image/jpg"
-
-
'Retrieving the name of the image to display
-
'(Yours is stored in Session)
-
imageName = Request.QueryString("imgName")
-
-
If String.IsNullOrEmpty(imageName) = False Then
-
'Retrieving the picture
-
imageUrl = String.Format("{0}{1}", _imagePath, imageName)
-
-
If IO.File.Exists(Server.MapPath(imageUrl)) Then
-
Dim fullSizeImg As System.Drawing.Image
-
fullSizeImg = System.Drawing.Image.FromFile(Server.MapPath(imageUrl))
-
ShowThumbnail(fullSizeImg )
-
' cleaning up the full size image
-
fullSizeImg.Dispose()
-
End If
-
End If
-
-
End Sub
-
-
Private Sub ShowThumbnail(ByVal imageToShow As System.Drawing.Image)
-
-
Dim imageWidth As Integer = imageToShow.Width
-
Dim imageHeight As Integer = imageToShow.Height
-
-
Dim newWidth As Integer
-
Dim newHeight As Integer
-
-
-
'Shrinking the image if it is large than the thumbnail dimensions
-
If imageHeight > _maxHeight Or imageWidth > _maxWidth Then
-
Dim scaleFactor As Double
-
'determine how to scale image: by height or width
-
Dim deltaWidth As Integer = imageWidth - _maxWidth
-
Dim deltaHeight As Integer = imageHeight - _maxHeight
-
-
If deltaHeight > deltaWidth Then
-
'difference between the max height and the height of the picture is greater
-
'that the difference between the max width and the width of the picture, so scale by height
-
scaleFactor = _maxHeight / imageHeight
-
Else
-
'difference between the max width and the width of the picture is greater
-
'that the difference between the max height and the height of the picture, so scale by width
-
scaleFactor = _maxWidth / imageWidth
-
End If
-
newWidth = CType(scaleFactor * imageWidth, Integer)
-
newHeight = CType(scaleFactor * imageHeight, Integer)
-
End If
-
-
'Creating the thumbnail image
-
Dim thumbnailImage As System.Drawing.Image
-
thumbnailImage = imageToShow.GetThumbnailImage(newWidth, newHeight, New System.Drawing.Image.GetThumbnailImageAbort(Function() False), IntPtr.Zero)
-
-
'Writing the thumbnail image directly to the output stream
-
thumbnailImage.Save(Response.OutputStream, ImageFormat.Jpeg)
-
-
'cleaning up the thumbnail image
-
thumbnailImage.Dispose()
-
End Sub
Now instead of having the image URL as a path to the image, you'd have the Image URL to the path of the Thumbnail.aspx page.
eg:
<asp:Image ImageURL="Thumbnail.aspx?thePicture.jpg" ID="theLowResImage" />
However, if the user was allowed to download the full size image the Thumbnail.aspx page will return the full size image instead of the thumbnail image.
You'd check your 'grant_download' Session variable to see if which version to return to the user.
Quote:
Originally Posted by captainB
After the save is successful, I set a session parameter called ["grant_download"] with a value of <filename>.
Now, lets assume the user has one filename in this variable, and would like to download another image. What would be a good way to maintain a list of filenames? I could concatenate to the variable like so: "image01.jpg_image02.jpg_image03.jpg" and slice the string (using the underscore character) into an array. I'd do this with each download request to check if the file is in the array and is permitted to download.
You can store Arrays in session...............
Quote:
Originally Posted by captainB
Since I'm using session variables, what would happen when the session ends as a result of a timeout?
Then the user would no longer be allowed to download the full size images.
In this case you'll have to go with your plan B:
Quote:
Originally Posted by captainB
One idea I had was to save these variables in the database along with the client's IP, and maybe compare the file requested and IP to a realtime request, which might eliminate the session timeout problem. However clients with dynamic IPs may cause a problem with this logic.
However, your Plan B is a little over complicated...I'd use Persistent Cookies instead ;)