Welcome Guest Search | Active Topics | Members

Saving the Second Thumbnail Options
JasonChandler
Posted: Tuesday, June 14, 2005 6:23:00 AM
Rank: Member
Groups: Member

Joined: 6/14/2005
Posts: 5
Points: 0
Hi all,

I am using the sample code to save my images, which is all working well, however I want to save a second thumbnail but the code is not working,

My Code Sample Below
==================

Code:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Get total number of uploaded files
        Dim intFileCount As Integer = CInt(Request.Form("FileCount"))

        Dim I As Integer, SourceFile As HttpPostedFile, ThumbnailFile As HttpPostedFile
        'We iterate through the uploaded files and save them and appropriate data
        For I = 1 To intFileCount
            'Get source image and save it to disk
            SourceFile = Request.Files("SourceFile_" & I)
            Dim strFileName As String = Path.GetFileName(SourceFile.FileName)
            'Check whether file with such name already exists and if so,
            'construct safe filename name (to avoid collision)
            Dim strNewFileName As String = strFileName
            Dim J As Integer = 1
            While File.Exists(Server.MapPath(strGalleryPath & Request.Form("albid") & "\" & strNewFileName))
                strNewFileName = J & "_" & strFileName
                J = J + 1
            End While
            strFileName = strNewFileName
            SourceFile.SaveAs(Server.MapPath(strGalleryPath & Request.Form("albid") & "\" & strFileName))

            'Get first thumbnail
            If Not Request.Files("Thumbnail1_" & I) Is Nothing Then
                ThumbnailFile = Request.Files("Thumbnail1_" & I)
                ThumbnailFile.SaveAs(Server.MapPath(strGalleryPath & Request.Form("albid") & "\" & "Thumbnails/" & strFileName & ".jpg"))
            End If

          'Get Second thumbnail
            If Not Request.Files("Thumbnail2_" & I) Is Nothing Then
                ThumbnailFile = Request.Files("Thumbnail2_" & I)
                ThumbnailFile.SaveAs(Server.MapPath(strGalleryPath & Request.Form("albid") & "\" & "Preview/" & strFileName & ".jpg"))
            End If


            'Save description to the database
            'ParameterName.Value = strFileName
            'ParameterWidth.Value = CInt(Request.Form("Width_" & I))
            'ParameterHeight.Value = CInt(Request.Form("Height_" & I))
            'ParameterDescription.Value = Request.Form("Description_" & I)
            'MyCommand.ExecuteNonQuery()

            objAlbum.InsertImagesToAlbum(CInt(Request.Form("albid")), _
                                         CInt(Request.Form("clientid")), _
                                         strFileName, _
                                         CInt(Request.Form("Width_" & I)), _
                                         CInt(Request.Form("Height_" & I)), _
                                         Request.Form("Description_" & I))



        Next


    End Sub


==================

However this is not working, any help would be gratley apperiacted.

Thanks

Jason Chandler

==================
Fedor
Posted: Tuesday, June 14, 2005 7:01:00 AM

Rank: Advanced Member
Groups: Administration , Member

Joined: 7/28/2003
Posts: 1,254
Points: -345
Location: WA, US
Hello Jason,

First of all I recommend you to read Debugging Server Scripts topic for general information about debugging.

In order to see server page response set ShowDebugWindow property to "True" value. If you use VS.NET then you can run your web project in debug mode and debug it as usual application.

If you will receive error trace please post it here, it will help us to solve the problem gracefully.

Right now I see the only one incorrect place in you code: you use backslashes in paths when pass them to Server.MapPath method at that time as you should slashes only:

>>>>>>>>>>>>>
Code:
While File.Exists(Server.MapPath(strGalleryPath & Request.Form("albid") & [b]"\"[/b] & strNewFileName))
    strNewFileName = J & "_" & strFileName
    J = J + 1
End While
strFileName = strNewFileName
SourceFile.SaveAs(Server.MapPath(strGalleryPath & Request.Form("albid") & [b]"\"[/b] & strFileName))

'Get first thumbnail
If Not Request.Files("Thumbnail1_" & I) Is Nothing Then
    ThumbnailFile = Request.Files("Thumbnail1_" & I)
    ThumbnailFile.SaveAs(Server.MapPath(strGalleryPath & Request.Form("albid") & [b]"\"[/b] & "Thumbnails/" & strFileName & ".jpg"))
End If

'Get Second thumbnail
If Not Request.Files("Thumbnail2_" & I) Is Nothing Then
    ThumbnailFile = Request.Files("Thumbnail2_" & I)
    ThumbnailFile.SaveAs(Server.MapPath(strGalleryPath & Request.Form("albid") & [b]"\"[/b] & "Preview/" & strFileName & ".jpg"))
End If

<<<<<<<<<<<<<

I think here is correct code:

>>>>>>>>>>>>>
Code:
While File.Exists(Server.MapPath(strGalleryPath & Request.Form("albid") & [b]"/"[/b] & strNewFileName))
    strNewFileName = J & "_" & strFileName
    J = J + 1
End While
strFileName = strNewFileName
SourceFile.SaveAs(Server.MapPath(strGalleryPath & Request.Form("albid") & [b]"/"[/b] & strFileName))

'Get first thumbnail
If Not Request.Files("Thumbnail1_" & I) Is Nothing Then
    ThumbnailFile = Request.Files("Thumbnail1_" & I)
    ThumbnailFile.SaveAs(Server.MapPath(strGalleryPath & Request.Form("albid") & [b]"/"[/b] & "Thumbnails/" & strFileName & ".jpg"))
End If

'Get Second thumbnail
If Not Request.Files("Thumbnail2_" & I) Is Nothing Then
    ThumbnailFile = Request.Files("Thumbnail2_" & I)
    ThumbnailFile.SaveAs(Server.MapPath(strGalleryPath & Request.Form("albid") & [b]"/"[/b] & "Preview/" & strFileName & ".jpg"))

End If

<<<<<<<<<<<<<

Best regards,
Fedor Skvortsov
Fedor
Posted: Tuesday, June 14, 2005 7:14:00 AM

Rank: Advanced Member
Groups: Administration , Member

Joined: 7/28/2003
Posts: 1,254
Points: -345
Location: WA, US
Jason, I also want to notice that the following code can compromise website security in some configuration:

>>>>>>>>>
Server.MapPath(strGalleryPath & Request.Form("albid") & "/" & strNewFileName)
<<<<<<<<<

Let's assume that malicious user will pass "../../../SomeOtherFolder/" value
in albid form field. In this case Server.Math method will return physical path out of strGalleryPath folder. If internet user account has write permissions to SomeOtherFolder folder, then the file will be saved out of strGalleryPath path.

So way you should check input data which come to you from client side. If albid should be an integer value, then you can check it with this easy code:

>>>>>>>>>
Server.MapPath(strGalleryPath & CInt(Request.Form("albid")) & "\" & strNewFileName)
<<<<<<<<<

If it is not integer, then server error will be raised. Sure it is better to check albid value once and add appropriate error handling.

Best regards,
Fedor Skvortsov
JasonChandler
Posted: Tuesday, June 14, 2005 7:42:00 AM
Rank: Member
Groups: Member

Joined: 6/14/2005
Posts: 5
Points: 0
Hi there thanks for the Help, I will take read through what you have you said.

The Form albid is a hidden form so the user will have a hard time to pass another value to it, but I take your point.

Thanks

Jason
Alex Makhov
Posted: Tuesday, June 14, 2005 9:31:00 PM

Rank: Advanced Member
Groups: Member

Joined: 8/3/2003
Posts: 996
Points: 1
Hello Jason,

What is the value of UploadThumbnail2FitMode property in your code? It equals to "Off" by default, so Image Uploader does not send the second thumbnail to the server in this way. You can read about it here.

Sincerely yours,
Alex Makhov
JasonChandler
Posted: Wednesday, June 15, 2005 3:43:00 AM
Rank: Member
Groups: Member

Joined: 6/14/2005
Posts: 5
Points: 0
Hi all,

@ Alex, thanks alot this got it woking for me. I actually figured this out yesterday, after much reading :'( .

All is good now

Great product by the way

Jason
Alex Makhov
Posted: Wednesday, June 15, 2005 3:59:00 AM

Rank: Advanced Member
Groups: Member

Joined: 8/3/2003
Posts: 996
Points: 1
Glad to help you :D

Sincerely yours,
Alex Makhov
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

YAFVision Theme Created by Jaben Cargman (Tiny Gecko)
Yet Another Forum.net version 1.9.1.6 running under Cuyahoga.
Copyright © 2003-2006 Yet Another Forum.net. All rights reserved.