|
Rank: Newbie Groups: Member
Joined: 7/1/2009 Posts: 5
|
Hello, I'd like to upload photos on my website with the AjaxUploader. But how can I immediately resize them so they are saved in a smaller format? Thanks for your reply!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi, You will need to handle the uploader's FileUploaded event. Inside that event you will get the file name of the newly uploaded files (depending on whether you set the uploader's FinalFileLoation, you may have a temp file name or a final file name. However this does not matter). Once you get the file name, you will code to read the file, resize it, then save it back to whatever name you want. Note this is to be done by your code, not the uploader. You can find a lot of sample code on this on the Internet though. It's a rather common task and the code is relatively simple. Here is one link with sample code that might help you to get an idea of how it is done: http://snippets.dzone.com/posts/show/4336Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 7/1/2009 Posts: 5
|
First of all, thanks for your reply! I bought EO today and it's great! I know how to resize a photo, that's no problem. So I have to do it in the FileUploaded event. OK. So I decided to upload the photos only in the TempFileLocation. The next step is to resave them in another location handling the uploader's FileUploaded event. That's my problem. How can I get the last saved picture in my tempFileLocation? I hope you understand... Thanks.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi, You will get the file name (uploader doesn't care whether it's a picture or not) through the uploader's PostedFiles property: http://doc.essentialobjects.com/library/1/eo.web.ajaxuploader.postedfiles.aspxHere is the sample code that displays the file name: http://demo.essentialobjects.com/Default.aspx?path=AJAXUploader\_i11Once you have the file name, you can do whatever you need to do. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 7/1/2009 Posts: 5
|
My Uploader is in a formview. I suppose this is a problem...
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
It should not. Why?
|
|
Rank: Newbie Groups: Member
Joined: 7/1/2009 Posts: 5
|
Hello, I managed to upload a photo using the AJAXUploader in my formview and to show the uploaded photo in an image in the same Formview. So far so good. Next step: I want to resave the original image as a thumbnail and show this thumbnail in my image in the formview instead of the original (too big) photo. I use the code that can be found here.(I got an error when i tried to post it here). I got the following error: 'System.IO.FileNotFoundException: ~/Images/fotos/fotoDavi_11.jpg' fotoDavi_11.jpg being the original photo. The code where this error was generated: Dim bm As Bitmap = System.Drawing.Image.FromFile("~/Images/fotos/" & strFileName) What can be wrong? Thanks for your help!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
"~/Images/fotos" is a virtual path that is relative to your web application. System.Drawing.Image.FromFile has nothing to do with your web application and it requires a real path. You need to call MapPath to convert the former to the later.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 7/1/2009 Posts: 5
|
I test it locally. I changed the code but I still got the error. The new code is Dim bm As Bitmap = System.Drawing.Image.FromFile(Server.MapPath("Images/fotos/") & strFileName) When I look into my image map I can see the original uploaded image. So the image is correctly saved. But it seems like the FinalFileName can't be found the way I try to get it...
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Please see your private message for our replies.
|
|