Small program upload pictures is very simple, take advantage of 2 API:
Wx.chooseimage
Wx.uploadfile
/*** Upload Images */ Chooseimageupload(){ varThat= This; WX.Chooseimage({ Count: 1, SizeType:[' original ', ' compressed '], sourcetype:[' album ', ' camera '], Success: function(RES){ that.tempfilepaths = Res.tempfilepaths; that.Uploadqiniu(); } })},
Note the point:
- Header to write
- Token must go and get the seven-ox token.
- FilePath is a single picture to write subscript 0, if a lot of pictures with for loop it, but the last function Wx.chooseImage.count to configure more than 1
- URL Write https://upload-z2.qiniup.com
/*** Upload seven kn back key */ Uploadqiniu(){ LetToken= This.Uploadtoken.token; LetTempfilepaths= This.tempfilepaths; varThat= This; WX.UploadFile({ URL: ' https://upload-z2.qiniup.com ', name: ' file ', FilePath:tempfilepaths[0], Header: { "Content-type": "Multipart/form-data" }, FormData: { token:Token, }, Success: function(RES){ LetData= JSON.Parse(Res.Data)// to do ... }, fail: function(RES){ Console.Log(RES)} })},
See Return key is successful!!
Small program upload image to seven kn