Small program upload image to seven kn

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.