Upload + Thumbnail Creation

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Upload + Thumbnail Creation

Guest-215
I use your control to upload images to my web server.  After the upload is complete, I create several thumbnails and do further validation such as making sure the file really is a .jpg file etc...  When the file is renamed to have a .jpg extension but really is not a .jpg, I detect this and delete the file so that it is no longer on the web server.  Unfortunately, the screen then refreshes and the progress bar complains that it can't find the file.  Is there a way to do this so that the progress bar knows that the file was bad?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Upload + Thumbnail Creation

Dean Brettle
Administrator
To avoid the error in the progress bar, don't delete the file yourself.  Instead only call InputFile.MoveTo() after you've successfully validated the file.  If you don't call MoveTo(), NeatUpload will automatically delete the file for you at the end of the request.

It's more complicated to do exactly what you want in terms of having the progress bar indicate that the file was bad.  You'd need to create a custom UploadStorageProvider that put the validation code in there instead of in the code for your page.  But...

An easier solution is to just have your page display the error message instead of the progress bar.  If you want to prevent most accidental uploads of the wrong types of files, you can use a RegularExpressionValidator to check that the filename ends with .jpg.  When client-side validation is enabled and available, this will also cause the user to see an error message before the upload even starts.

Hope that helps,

--Dean
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Upload + Thumbnail Creation

Guest-215
Thanks for the help.  Currently I am creating the thumbnails after the moveto command.  Is there a way to get a mapped path to the uploaded file before I do the moveto command?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Upload + Thumbnail Creation

Dean Brettle
Administrator
You can use InputFile.TmpFile if you are using the FilesystemUploadStorageProvider (which is the default).  However, it's use is deprecated since not all UploadStorageProviders can support it.  I better way would be to use InputFile.FileContent to get a Stream on the file and then copy that stream to another file or use it directly to create your thumbnails etc.  Of course, if you copy it to another file you'll need to remember to remove that  file if validation fails. 

Also, if you access InputFile.FileContent, be sure to close the Stream it gives you when you are done with it.

--Dean
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Upload + Thumbnail Creation

Guest-215
Works like a charm!  Thanks!

I don't even need the moveto command anymore.  I just use the stream and when I'm done the uploaded file gets automatically deleted.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Upload + Thumbnail Creation

Pulsman
How do you create thumbnails after uploading?

pulsman@gmail.com
Loading...