WeChat small procedure batch upload pictures to seven cattle (recommended)

First, introducing seven cattle SDK

Specific view of document

https://github.com/gpake/qiniu-wxapp-sdk/blob/master/ ReadMe.md

 / ** * Upload function * / const qiniuuploader = request ("qiniuuploader"); const request = required ("./ Request.js") // Initialization Seven Cow Related Parameters Function initQiniu () {var options = {UPLOADURL: 'https://up.qiniup.com', Region : 'ECN', // Uptokenurl: Request.ur + 'qiniu-token? Token =' + getApp (). GlobalData.token, // uptoken: 'xxxx', domain: 'cdn-mpsoft.tujihome.com/' ,};};} function upload (filepath, sucps, fail) {initQiniu (); // handed over QiniUuploader.upload (filepath, (res);} => {Success (res);} , (error) => {Console.Error ('error:' + json.stringify); fail (Error)); Fail (Error));Error);});} / ** * Bulk upload * @Param images * / Function Batchupload (images) {let Uplist = [] for (Let Index In Image) {const path = images [index] ['url'] Const key = images [index] ['key']; let promise = new promise (resolve, reject) => {qiniuuploader.upload (path, (res) => {resolve (res.imageurl)}, (Error) ) => {reject (error)}} {UPLOADURL: 'https://up.qiniup.com', region: 'ecn', // uptokenurl: Request.ur + 'qiniu-token? token =' + getApp ) .GlobalData.token, key: key, domain: 'cdn-mpsoft.tujihome.com/',});}) uplist.push (promise)}} }.com}}}}} }.com Console.log (resultlist); returnratelist;}, error => {console.log (error) throw err;})}}}} {'upload': Upload, 'Batchupload': Batchupload,}   URL: File path, key: file name 
Batchupload () incoming array, contains file path followed by file name, does not need to customize file names to modify, only call once initialization method,

return value is an array containing all file paths

UPLOADIMAGE (Image) {var this = this var imageurl = []; for (var i ify) {i.key = ‘gCLW_’ + Date.Parse (New Date ()) + Math.random () + ‘.jpg’;} Try {ImageURL = UPLOAD.BATCHUPLOAD (images); Return Imageurl;} catch (e) {wx.ShowModal ({Title: ‘Tips’, Content: E, Showcancel: False,})}},

Results
   
Summary

The above is a small-knitted microconger introduced by the microbused picture to the seven cattle, I hope everyone can help, if everyone has any If you have questions, please leave a message, the small package will reply to everyone in time. It is also veryThank you for your support of Tumi Cloud Website!

If you think this article helps you, welcome to reprint, please indicate the source, thank you! 微信小程序批量上传图片到七牛(推荐)

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment