You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
上传接口可以参考 cloudinary 图床接口(不用一样,仅参考)。由于 curl 的 POST 上传会携带 x-www-form-urlencoded 请求头, data URI 数据还进行了 urlencoded 。
curl -X POST https://api.cloudinary.com/v1_1/<cloud name>/image/upload --data 'file=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4%2F%2F8%2Fw38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg%3D%3D×tamp=1563412399&public_id=curlPost&api_key=<your api key>&signature=<sha-1 signature>'
// overload upload method to make options object optional
// b64 string can include MIME or not, options can include mime or not
// options override string for MIME
// options has optional keys: headers, params, mime
this.upload = function(b64, options, cb){
if (arguments.length < 2 || arguments.length > 3){
throw "Argument error. Make sure the arguments provided are valid.";
}
// handle two arguments provided
if (arguments.length == 2){
cb = options;
options = {};
}
var descriptor = {};
var commaIndex = b64.indexOf(",");
if (commaIndex == -1){
descriptor = {bare: b64, mime: null};
} else {
semicolonIndex = b64.indexOf(";");
descriptor = {bare: b64.substring(commaIndex + 1), mime: b64.substring(5, semicolonIndex)};
}
var mime = descriptor.mime;
if (options.mime){
mime = options.mime;
}
if (!mime){
throw "No mime specified. You need to specify a mime string (e.g. 'image/png') either in the base64 input or the options argument.";
}
file = new Buffer(descriptor.bare, 'base64');
var paramsString = "";
for (key in options.params){
paramsString = paramsString.concat("&" + key + "=" + options.params[key]);
}
if (paramsString){
paramsString = "?".concat(paramsString.substring(1));
}
var requestHeaders = {};
if (options.headers){
requestHeaders = options.headers;
}
requestHeaders["Content-Type"] = mime;
var requestUrl = "";
if (!options.url){
if (!this.getApiUrl()){
throw "No API URL specified. Use setApiUrl to set a URL";
}
requestUrl = this.getApiUrl() + paramsString;
} else {
requestUrl = options.url + paramsString;
}
request.post({url: requestUrl, body: file, headers: requestHeaders}, cb);
}
}
The text was updated successfully, but these errors were encountered:
前置阅读 | Pre-reading
PicList的版本 | PicList Version
v2.9.3
系统信息 | System Information
Mac
功能请求 | Feature request
内置Server的上传接口支持上传 data URI 形式的文件。
网页在展示某些图片时会使用内嵌的 data URI 形式的图片,简悦在上传这些图片到 PicList 时需要这个接口。
原始图片和 data URI 形式图片转换可以在这个网站进行测试。
上传接口可以参考 cloudinary 图床接口(不用一样,仅参考)。由于 curl 的 POST 上传会携带 x-www-form-urlencoded 请求头, data URI 数据还进行了 urlencoded 。
data URI 形式数据拆分可以参考这部分源码:
The text was updated successfully, but these errors were encountered: