在Buddy平台上创建(上传)图片

时间:2014-06-24 16:10:47

标签: javascript image upload sdk buddy.com

我正在尝试与Buddy upload a picture(后端即服务)。

我正在使用Buddy JS SDK,我有一个错误:

这是我的代码:

$(document).ready(function(){

Buddy.init("api_key", "api-id");

 Buddy.post("/pictures", {data : "data:image/vnd.microsoft.icon;base64,AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAgAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAZswzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAERABEREAAAAREAEREQAAABEQEQABEAAAAAARAAEQAAAAABEAARAAAAAAEQABEAAAAAARAAEQAAAAABEAARAAAAAAEQABEAAAAAARAAEQAAAAABEAARAAAAAAEQABEAAAAAABEREAAAAAAAEREQAAAAAAAAAAAAD//wAAxg8AAMYPAADE5wAA/OcAAPznAAD85wAA/OcAAPznAAD85wAA/OcAAPznAAD85wAA/g8AAP4PAAD//wAA"
  },  function(err, docs) {
    if (err) console.log("err is" +err);
    console.log("picture is" +docs);
});   
});

这是错误

{"status": 400,
 "error": "ParameterIncorrectFormat",
 "errorNumber": 515,
"message": "Can not convert 'data:image/vnd.microsoft.icon;base64,AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAA…YPAADE5wAA/OcAAPznAAD85wAA/OcAAPznAAD85wAA/OcAAPznAAD85wAA/g8AAP4PAAD//wAA' to HttpPostedFileBase.",
"request_id": "53a99fed426ac909a00b221a",
"success": false 
}  : 

我试过

"base64,AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAgAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAZswzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAERABEREAAAAREAEREQAAABEQEQABEAAAAAARAAEQAAAAABEAARAAAAAAEQABEAAAAAARAAEQAAAAABEAARAAAAAAEQABEAAAAAARAAEQAAAAABEAARAAAAAAEQABEAAAAAABEREAAAAAAAEREQAAAAAAAAAAAAD//wAAxg8AAMYPAADE5wAA/OcAAPznAAD85wAA/OcAAPznAAD85wAA/OcAAPznAAD85wAA/g8AAP4PAAD//wAA"

"AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAgAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAZswzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAERABEREAAAAREAEREQAAABEQEQABEAAAAAARAAEQAAAAABEAARAAAAAAEQABEAAAAAARAAEQAAAAABEAARAAAAAAEQABEAAAAAARAAEQAAAAABEAARAAAAAAEQABEAAAAAABEREAAAAAAAEREQAAAAAAAAAAAAD//wAAxg8AAMYPAADE5wAA/OcAAPznAAD85wAA/OcAAPznAAD85wAA/OcAAPznAAD85wAA/g8AAP4PAAD//wAA"

我总是有这个错误。

我已经使用Google

测试了谷歌图片和服务http://base64image.org/

pictureImagesintégrées1

raw:"iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAMcklEQVR42u2c+3NV1RXH/RP6J/CrPIMPUjQYA4gUWx3s1GkpHTPTiu1oB1u0LQhJSMIjBkKIAykvC2LxBRIqr6qQgtU6RojFKtBadIagbQXyuOfm3iDM7lk39yTnnnv2Pnvtx7n7xJ2Z7y8MzDD381lrr73OubmJEHKTzTc39kOwAtgPwQpgYwWwsQLYWAFsrAA2VgAbK4CNFcDGCmBjBbCxAthYAWysADZWgKJ/HPIzd+P1ajedbsi9rdfJHC8bIF+Te/xZP5xZuVwbzrprZGazP0O53P2Mm6bCVDZlSeVaN2uGc5c/qzNkxqoMqQjJnY2D5M6G0dwBqYekRzLdzbdX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nAlgceDR4f97/F99MAH8vSfCNEaD59VQMsHHQ/ZnX1M91RcwJgAFfYvgTfvVfMwT4mXsHVweYDV10bdvOsSwCAUTAlwq+MQJM1QFcAfRgF4jcBZxJqan6mOCPHzsCqAcelrMX2bPA5jcGEgU/gQL0hcLWBTx4p4cpnyXA8pf7lbZ85fDzAow3TwA62NhB07Z4btrfYO8FvrO2T1nVR+32VcAf/8R/zBCgrBRgEeC9a91mhgAXv3LEqr6E8I0RgLpDNwC6/1rX8T79CNh9ckBt1euEb5oAQi9UaAYf1so/YQyBI+1fRdWz4FN2+yLwbzZFAK5n6TFXezAVtb3s658EeJ6WrwO+KQJ0wr7dROj+wIRPrf41JWr5gvB9AnSaIEA16pUqUeAC0P2BIS/07D8xIF/1pYC/+EtIdckFyEvQ/VBbv1rYCqB7oU3/IEVFDQO8RNULwQ8seSLgd8Nnb4oA4159L9UrBToAWwa4Pw+19lFb/w829GqpeuZ5H3iezwv/5kL4vW7GGSOAJ4ELsZsJmAFbFfAgfNpTwOUv9esBL9jyJ0Sf9yOV78E3SgDvx4Vb7cLsDAOsC3TYAmfxTiR8CnhVVS8N3x344MwPft4lFcAm+bEfghXAfghWABsrgI0VwMYKYGMFsLEC2FgBbKwANlYAGyuAjRXAxgpgYwWwGZP5PwU4jFblpUEkAAAAAElFTkSuQmCC"

我也有这个错误。

如何让图片上传工作?

1 个答案:

答案 0 :(得分:1)

对于data参数的值,您应该传递JavaScript文件或Blob对象。以下是使用jQuery和SDK(https://github.com/BuddyPlatform/Buddy-JS-SDK)的简短示例:

<input type="file" id="file" name="file" />
<input id="uploadButton" type="button" value="Upload" />

<script type="text/javascript">
    $(document).ready(function () {
        $("#uploadButton").click(function () {
            var fileInput = $("#file")[0];

            // get a key and id from http://buddyplatform.com
            Buddy.init("api_key", "api-id");

            Buddy.loginUser("testuser", "testpassword");

            Buddy.post("/pictures", {
                data: fileInput.files[0]
            });
        });
    });
</script>

如果需要显式发送base64字符串,则需要发出多部分MIME POST请求,这是Buddy SDK代表您执行的操作。如果您查看SDK本身,那里的代码可以指导您。