【发布时间】:2017-08-22 08:05:51
【问题描述】:
我正在使用 javascript 使用未签名模式上传图像。生成的图像是空白图像,或者我可以说是填充黑色的图像。不知道出了什么问题。代码如下:
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "https://api.cloudinary.com/v1_1/mycloud/image/upload", false);
xhttp.setRequestHeader("Content-type", "application/json");
xhttp.onreadystatechange = function() { //Call a function when the state changes.
if (xhttp.readyState == 4 && xhttp.status == 200) {
alert(xhttp.responseText);
} else {
alert("Error dude: " + xhttp.statusText);
}
}
var parameters = {
"file": imgData,
"upload_preset": "mycode"
};
xhttp.send(JSON.stringify(parameters));
结果图像是:
http://res.cloudinary.com/viksphotography/image/upload/v1490752341/irgvt7b3qwoug1vz7own.jpg
请注意 imgData 是 base64 编码的
【问题讨论】:
标签: javascript cloudinary