【发布时间】:2011-05-21 04:28:42
【问题描述】:
大家好,我正在开发一个工作站点,它将使用 Wordpress XML RPC 将信息从数据库推送到 Wordpress。我可以获取信息并发布它就好了,但是当我上传图像时它似乎可以工作(WP Media Tab 中没有运行时错误/图像)但是它上传了一个损坏的图像链接。似乎以某种方式无法从我的图像中获取数据,我不确定为什么这是我的一些代码。
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));
在该代码加载图像信息后,我以数据变量的格式将其传递给函数
var data = new Data
{
Base64 = Convert.ToBase64String(imagebytes),
Name = "DownloadButton-PSD.png",
Type = "image/png",
Overwrite = false,
};
_wpWrapper.UploadFile(data);
仅供参考:我也在使用来自的 dll http://joeblogs.codeplex.com/ 我的项目
数据类如下所示:
public class Data
{
public string Name { get; set; }
public string Type { get; set; }
public string Base64 { get; set; }
public bool Overwrite { get; set; }
}
上传文件功能如下:
public void UploadFile(Data data)
{
var xmlRpcData = Map.From.Data(data);
var result = _wrapper.UploadFile(this.BlogID, Username, Password, xmlRpcData);
}
【问题讨论】:
-
基本上不,在我这样做的时候,JoeBlogs 代码库是不完整的。从我所见,尽管您想使用 MediaObjects 而不是 Files。
-
在此处查看解决方案。它可能适用于旧版本,但您应该可以使用它,http://pixpuffindev.blogspot.com/2012/08/posting-to-wordpress-with-c-using.html
标签: c# image wordpress file-upload