Upload photos?

Feb 21, 2010 at 1:09 AM

The metaweblog should support fileupload but when I try to upload a picture I get a error message telling me that my blog isn't supporting fileuploading.

I have this options added to my manifest.xml





Feb 21, 2010 at 1:18 AM

Ah now I got it. The code was sending an exception so the function never returned anything. But now it returns an empty string so atleast I dont get the error no more.

But how do I get info about the image width and height that the use can change from WLM?

When an image is added it gets handled that can be used to change the size of the image but If I want to use this information to resize the image before I save it, how do i retrive it?

Feb 21, 2010 at 10:11 AM

when your user adds an image to wlw he can resize it in wlw, then wlw makes two uploads (original and thumbnail). If you really wish you can resize your file when you save it on your server, you should be able to check for dimensions when file is saved, not sure how, i never tried that.

Feb 21, 2010 at 11:33 AM

ah right. I just noticed that. But how do I get access to the file and save it on my webserver?

Do i need to use the "File.WriteAllBytes" method?

Feb 21, 2010 at 12:06 PM

you can save it however you like it, i used file.writeallbytes because i find it most convenient

Feb 21, 2010 at 12:15 PM

Ah yeah but how do I use that method? I tried it but I dont really know how to use it.

Feb 21, 2010 at 12:21 PM

            string fileUrl = HttpContext.Current.Request.PhysicalApplicationPath + @"somedir\filename.jpg";
            File.WriteAllBytes(fileUrl, mediaObject.bits);

Feb 21, 2010 at 1:53 PM
Edited Feb 21, 2010 at 2:07 PM

I guess that saves the file in a folder in WLM but how do I then save it on my webserver?

Thanks for you help.



edit: I tried your code but it didnt work. What is the @ character doing? Do i need to specify a folder that exists or?

Feb 21, 2010 at 2:10 PM

Just so I could see what PhysicalApplicationPath looked like I used this code for sending it to a string:


string testing = HttpContext.Current.Request.PhysicalApplicationPath.ToString();

But with this line i the code the WLW stopped the saving process giving me the error saying the blog doesnt support embedding.


Feb 21, 2010 at 2:50 PM

my code saves file to your server.

this error you get might be because embeding is not approved in wlwmanifest ?

Feb 21, 2010 at 8:17 PM

oh... lol sorry... I thought that the "applicationdir" was the local directory of WLW. :P

Then I get it. :)

supportsEmbeds is enabled and that code isn't saving anything it just puts a value inside the string "testing" so my guess is it comes from something else beside the options of the manifest file.

You can see in my first post what options I have enabled.

Feb 22, 2010 at 7:19 AM

@ sing is for literal string definition.

is there any error when you upload images?