Hi guys,
I'm trying to create an admin page where you can upload images, resize them and save them.
Didn't really want to get into .NET GDI, so I thought I take the easy option and use ASPUpload and ASPJpeg using the following...
If Page.IsPostBack Then
Dim Upload = Server.CreateObject("Persits.Upload")
' Compute path to save uploaded files to
Dim Path = Server.MapPath("/images")
' Capture uploaded file. Return the number of files uploaded
Dim Count = Upload.Save
If Count = 0 Then
Response.Write("No images selected.")
Response.End()
Else
' Obtain File object representing uploaded file
Dim File = Upload.Files(1)
' Is this a valid image file?
If File.ImageType <> "UNKNOWN"Then
' Create instance of AspJpeg object
Dim jpeg = Server.CreateObject("Persits.Jpeg")
' Open uploaded file from memory
jpeg.OpenBinary(File.Binary)
' Resize image according to "scale" option.
' We cannot use Request.Form, so we use Upload.Form instead.
jpeg.Width = jpeg.OriginalWidth * Upload.Form("scale") / 100
jpeg.Height = jpeg.OriginalHeight * Upload.Form("scale") / 100
Dim SavePath = Path & File.ExtractFileName
' AspJpeg always generates thumbnails in JPEG format.
' If the original file was not a JPEG, append .JPG ext.
If UCase(Right(SavePath, 3)) <> "JPG"Then
SavePath = SavePath & ".jpg"
EndIf
jpeg.Save(SavePath)
Response.Write("Success!")
Else
Response.Write("This is not a valid image.")
Response.End()
EndIf
EndIf
EndIf
I get an exception though...
Security Exception
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Source Error:
Line 5: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadLine 6: If Page.IsPostBack ThenLine 7: Dim Upload = Server.CreateObject("Persits.Upload")Line 8: ' Compute path to save uploaded files toLine 9: Dim Path = Server.MapPath("/images")
Anyone got any ideas? Looks like permissions, but I thought ASPUpload was enabled on RFH by default?
Cheers
Chris


Reply With Quote

Bookmarks