【问题标题】:Failing to upload Image in base64 bits via XML-RPC [Wordpress/NGG]无法通过 XML-RPC [Wordpress/NGG] 上传 base64 位图像
【发布时间】:2012-09-14 08:16:13
【问题描述】:

我已经尝试了所有可能的方法,但显然我无法找出正确的方法。

我正在尝试将图像上传到安装在 wordpress 博客上的下一代画廊。关于 xml-rpc 的一切都在工作,因为我可以用它做所有其他的事情。

问题是服务器返回一个错误,说图像不是有效的。很明显,问题出在base64上。但是,出于测试目的,我复制并检查了 base64 字符串并意识到它是正确的,它使用外部 base64 到图像转换器将正确转换为图像。

这是提交查询的行。

    result = categories.newImage(1, "admin", "password", newImage);

newImage 的结构是;

    public struct imageI
    {
        public string name;
        public string type;
        public string bits;
        public bool overwrite;
        public int gallery;
        public int image_id;

    }

这就是初始化新图像的方式,以及将图像转换为 base64 的方式

        //Creating the image base64 string
        string filename = "asd.jpg";
        Image image1 = Image.FromFile(filename);
        string base64 = ImageToBase64(image1, image1.RawFormat);
        //for test purposes i copied and checked the base64 and it is just right, it converts right to the image using an external base64 to image converter.
        Clipboard.SetText(base64);

        //Creating a newImage 
        imageI newImage = default(imageI);
        newImage.name = "newImage";
        newImage.bits = base64;
        newImage.gallery= 86;

最后是我的方法“ImageToBase64(Image, ImageFomat)”;

    public string ImageToBase64(Image image, System.Drawing.Imaging.ImageFormat format)
    {
        using (MemoryStream ms = new MemoryStream())
        {
            // Convert Image to byte[]
            image.Save(ms, format);
            byte[] imageBytes = ms.ToArray();

            // Convert byte[] to Base64 String
            string base64String = Convert.ToBase64String(imageBytes);
            return base64String;

        }
    }

【问题讨论】:

    标签: c# wordpress base64 xml-rpc nextgen-gallery


    【解决方案1】:

    万一有人碰到这个问题,我想通了,就行了; newImage.name = "newImage";文件名应该和你上传的一样,或者至少应该有相同的扩展名,以便xml-rpc文件中的函数可以解析扩展名并检查是否可以上传。

    【讨论】:

      猜你喜欢
      • 2011-05-21
      • 1970-01-01
      • 2013-07-15
      • 2012-02-10
      • 1970-01-01
      • 1970-01-01
      • 2013-02-08
      • 2011-02-27
      • 2012-09-03
      相关资源
      最近更新 更多