问题描述
嘿,我开发将使用Wordpress XML RPC推动信息从数据库到WordPress工作的网站。我可以抓取信息,并张贴就好了,但是当我去上传图片的地步,似乎工作(在WP媒体选项卡中没有运行时错误/图片)但它上传一个破碎的图片链接。这似乎是不知何故没有得到从我的图像的数据,我不能确定为什么在这里是我的一些代码。
的MemoryStream毫秒=新的MemoryStream();
为System.Drawing.Image IMG = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(_图像/ DownloadButton-PSD.png));
img.Save(MS,ImageFormat.Png);
字节[] = imagebytes新的字节[ms.Length]
ms.Position = 0;
ms.Read(imagebytes,0,Convert.ToInt32(ms.Length));
这代码加载图像信息,我将它传递给函数在数据变量的格式后
VAR数据=新的Data
{
的Base64 = Convert.ToBase64String(imagebytes),
NAME =DownloadButton-PSD.png,
TYPE =图像/ PNG,
覆盖=假,
};
_wpWrapper.UploadFile(数据);
FYI:我也使用来自
http://joeblogs.codeplex.com/
为我的项目
数据类看起来是这样的:
公共类数据
{
公共字符串名称{;组; }
公共字符串类型{搞定;组; }
公共字符串的Base64 {搞定;组; }
公共BOOL覆盖{搞定;组; }
}
的
上传文件功能如下:
公共无效UploadFile(的数据)
{
VAR xmlRpcData = Map.From.Data(数据);
VAR的结果= _wrapper.UploadFile(this.BlogID,用户名,密码,xmlRpcData);
}
在JoeBlogs库尝试使用类 MetaWeblogWrapper
和方法: MediaObjectInfo NewMediaObject(媒体目标的mediaObject)
- 上传图片。
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 fromhttp://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.
这篇关于WordPress的XML RPC上传图片C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!