Welcome Guest Search | Active Topics | Sign In | Register

Resize photos with AJAXUploader Options
David
Posted: Wednesday, July 1, 2009 3:41:42 PM
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!
eo_support
Posted: Wednesday, July 1, 2009 3:47:23 PM
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/4336

Thanks!
David
Posted: Wednesday, July 1, 2009 4:06:06 PM
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.
eo_support
Posted: Wednesday, July 1, 2009 4:12:57 PM
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.aspx

Here is the sample code that displays the file name:

http://demo.essentialobjects.com/Default.aspx?path=AJAXUploader\_i11

Once you have the file name, you can do whatever you need to do.

Thanks!
David
Posted: Wednesday, July 1, 2009 4:56:30 PM
Rank: Newbie
Groups: Member

Joined: 7/1/2009
Posts: 5
My Uploader is in a formview. I suppose this is a problem...
eo_support
Posted: Wednesday, July 1, 2009 5:00:04 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
It should not. Why?
David
Posted: Thursday, July 2, 2009 4:47:23 PM
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!
eo_support
Posted: Thursday, July 2, 2009 4:51:52 PM
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!
David
Posted: Thursday, July 2, 2009 5:25:03 PM
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...
eo_support
Posted: Thursday, July 2, 2009 5:26:08 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Please see your private message for our replies.


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.