function uploadImgToQiniu(e, n, t) {
var o = [],
i = [];
Array.isArray(e) ? i = e : i.push(e), $.api("token", {}, function(e) {
var r = e.data.token;
i.forEach(function(e) {
var a = new Image();
a.onload = function() {
var s, u, c = a.width,
l = a.height,
f = 1200;
(c > f || l > f) && (c >= l ? (s = f + "px", u = "auto") : (u = f + "px", s = "auto"));
var d = userInfo.myInviteCode + "_" + Date.now() + ".jpg",
p = "_downloads/" + d;
plus.zip.compressImage({
src: e,
dst: p,
overwrite: !0,
format: "jpg",
quality: 60,
width: s,
height: u
}, function(e) {
var a = e.target,
s = plus.uploader.createUpload(config.qiniuUpload, {
method: "POST"
}, function(e, r) {
if(200 == r) {
var a = JSON.parse(e.responseText);
o.push(a.key), o.length === i.length && n(o);
} else t("\u4e0a\u4f20\u5931\u8d25");
del_file(p);
});
s.addData("token", r), s.addFile(a, {
key: "file"
}), s.addData("key", d), s.start();
}, function(e) {
t("\u4e0a\u4f20\u5931\u8d25");
});
}, a.src = e;
});
}, function(e) {
t("\u4e0a\u4f20\u5931\u8d25");
}, function() {
t("\u7f51\u7edc\u9519\u8bef\uff0c\u4e0a\u4f20\u5931\u8d25");
}, function() {});
}
6 个回复
6***@qq.com
你好解决了吗?我现在也遇到了这个问题。如果解决了麻烦告诉一声 谢谢
Trust - 少说废话
http://ask.dcloud.net.cn/question/2796
t***@qq.com
使用html5+ 的 uploader模块
f***@163.com
function uploadImgToQiniu(e, n, t) {
var o = [],
i = [];
Array.isArray(e) ? i = e : i.push(e), $.api("token", {}, function(e) {
var r = e.data.token;
i.forEach(function(e) {
var a = new Image();
a.onload = function() {
var s, u, c = a.width,
l = a.height,
f = 1200;
(c > f || l > f) && (c >= l ? (s = f + "px", u = "auto") : (u = f + "px", s = "auto"));
var d = userInfo.myInviteCode + "_" + Date.now() + ".jpg",
p = "_downloads/" + d;
plus.zip.compressImage({
src: e,
dst: p,
overwrite: !0,
format: "jpg",
quality: 60,
width: s,
height: u
}, function(e) {
var a = e.target,
s = plus.uploader.createUpload(config.qiniuUpload, {
method: "POST"
}, function(e, r) {
if(200 == r) {
var a = JSON.parse(e.responseText);
o.push(a.key), o.length === i.length && n(o);
} else t("\u4e0a\u4f20\u5931\u8d25");
del_file(p);
});
s.addData("token", r), s.addFile(a, {
key: "file"
}), s.addData("key", d), s.start();
}, function(e) {
t("\u4e0a\u4f20\u5931\u8d25");
});
}, a.src = e;
});
}, function(e) {
t("\u4e0a\u4f20\u5931\u8d25");
}, function() {
t("\u7f51\u7edc\u9519\u8bef\uff0c\u4e0a\u4f20\u5931\u8d25");
}, function() {});
}
立树 - 前端程序猿
写了篇七牛图片上传的技术分享:使用 uploader 进行七牛图片上传
.
先贴出文章的代码,详细内容还是去看文章吧。
7***@qq.com
我使用的是houheaven - 前端程序猿 提供的方法,可以一直报401的错误!有没有解决了的?