HBuilder 上传支持表单上传,所以上传到七牛云的时候用的也是表单上传
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
function uploadToQiniu(imgPath){ var domain = "http://onpzdyxr0.bkt.clouddn.com/"; var randName = Math.random().toString(36).substr(2) + imgPath.match(/\.?[^.\/]+$/); var task = plus.uploader.createUpload( "http://upload.qiniu.com/", { method: "POST", blocksize:204800, priority:100 }, function ( t, status ) { if ( status == 200 ) { console.log( "Upload success: " + t.url ); var imgUrl = domain + randName; } else { console.log( "Upload failed: " + status ); } } ); task.addFile(imgPath,{key: "file",mime: "image/*"}); task.addData("key",randName); task.addData("token",token); task.start(); }
|
参考资料:
七牛云表单上传官方文档 >>
HBuilder 上传官方文档 >>