Last post Feb 23, 2020 06:31 PM by carrzkiss
Feb 23, 2020 12:52 PM|carrzkiss|LINK
VB.net Upload to the local system, no issues. (Local meaning, my development system (OR) on running the site on the live server)
I am now uploading all files to a dedicated file server, so I am uploading it to a network share.
It will upload the actual IMAGE file.
Where the issue is at, is the RESIZE function.
I read that I will need to leave the memory stream open.
However, that does not make sense, considering I have used this code on all my image upload sites for the last 8+ years. And when I upload this same script to upload to the local system, it uploads all image sizes.
It cannot be a permissions issue, as the original file gets uploaded to the server.
I watch it come into the folder during the upload process.
So, permissions are there. Just the resize issue is causing a problem.
Code for FUNCTION
Private Shared Function resizeImage(ByVal imgToResize As Image, ByVal size As Size) As Image
Dim sourceWidth As Integer = imgToResize.Width
Dim sourceHeight As Integer = imgToResize.Height
Dim nPercent As Single = 0
Dim nPercentW As Single = 0
Dim nPercentH As Single = 0
nPercentW = (CSng(size.Width) / CSng(sourceWidth))
nPercentH = (CSng(size.Height) / CSng(sourceHeight))
If nPercentH < nPercentW Then
nPercent = nPercentH
nPercent = nPercentW
Dim destWidth As Integer = CInt((sourceWidth * nPercent))
Dim destHeight As Integer = CInt((sourceHeight * nPercent))
Dim b As New Bitmap(destWidth, destHeight)
Dim g As Graphics = Graphics.FromImage(DirectCast(b, Image))
g.InterpolationMode = InterpolationMode.HighQualityBicubic
g.DrawImage(imgToResize, 0, 0, destWidth, destHeight)
Return DirectCast(b, Image)
Code where the error is pointing.
filMyFile.PostedFile.SaveAs(Convert.ToString(savepath & "\") & Convert.ToString(getfile))
Dim ImageToSave As Image = resizeImage(Image.FromStream(filMyFile.PostedFile.InputStream), New Size(110, 130))
Error >> ImageToSave.Save((Path.Combine(thPath, getfile.Insert(getfile.LastIndexOf("."c), ""))), ImageFormat.Jpeg)
Any help on this issue would be greatly appreciated.
Feb 23, 2020 02:35 PM|mbanavige|LINK
If i had to guess, it would be that you're trying to save the newly resized file on top of your original file and you still have a file handle open against that original file.
Are you sure you didn't mean to rename the resized file (thus creating a new file) by inserting the new dimensions into the file name?
ImageToSave.Save((Path.Combine(thPath, getfile.Insert(getfile.LastIndexOf("."c), "110x130"))), ImageFormat.Jpeg)
Feb 23, 2020 06:31 PM|carrzkiss|LINK
I fixed it.
In the path to the network share, I had
I changed it to
And it went to working.
All good now.
Feb 23, 2020 08:25 PM|carrzkiss|LINK
Please have a look at the demo upload script.
It has ALL the code for uploading to the machine.
Please read the README.txt file.
Download the script here.