Hey all, I am developing a site for work that will push info from a database into WordPress using WordPress XML RPC. I can grab info and post it just fine, however when I get to the point of uploading images it seems to work(no runtime errors/image in WP Media Tab) however it uploads a broken image link. It appears it is somehow no getting the data from my image and I am not certain why here is some of my code.
MemoryStream ms = new MemoryStream();
System.Drawing.Image img = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath("_Images/DownloadButton-PSD.png"));
img.Save(ms, ImageFormat.Png);
byte[] imagebytes = new byte[ms.Length];
ms.Position = 0;
ms.Read(imagebytes, 0, Convert.ToInt32(ms.Length));
after that code loads the image info I pass it to the function in the format of a Data variable
var data = new Data
{
Base64 = Convert.ToBase64String(imagebytes),
Name = "DownloadButton-PSD.png",
Type = "image/png",
Overwrite = false,
};
_wpWrapper.UploadFile(data);
FYI: I am also using the dll’s from
http://joeblogs.codeplex.com/
for my project
The Data Class looks like this:
public class Data
{
public string Name { get; set; }
public string Type { get; set; }
public string Base64 { get; set; }
public bool Overwrite { get; set; }
}
The Upload File Function looks like this:
public void UploadFile(Data data)
{
var xmlRpcData = Map.From.Data(data);
var result = _wrapper.UploadFile(this.BlogID, Username, Password, xmlRpcData);
}
In JoeBlogs library try using the class
MetaWeblogWrapper
and method:MediaObjectInfo NewMediaObject(MediaObject mediaObject)
– for upload image.