This article tells the small program development encountered cannot upload the solution, everybody to the small program development encounters cannot upload the solution not to understand the words or to the small program development encounters cannot upload the solution to be interested in the words then we will take a look at this article, the good nonsense to go to the point!
Small program Wx.uploadfile Unable to upload the workaround
There are many developers who are unable to upload files using Wx.uploadfile on the Android client.
I also because have been unable to solve, bite the bullet to submit the audit was rejected (with the best use of iOS detection of the mentality, unfortunately audit my application is the use of Android), only try to use third-party means to solve.
In the end, I used seven cows. Third-party storage, upload files directly to seven cows in the storage space and then callback use.
Of course it's like a cloud, Vientiane. These third-party storage sources can use this approach.
The first is to put seven of the HTTPS upload domain name into the applet domain name list.
Here I use the domain name https://up.qbox.me of seven cattle East area.
Applet Wx.uploadfile uses the Multipart/form-data way to upload, that is, form upload.
According to the official documentation of the seven cattle http://developer.qiniu.com/docs/... up/form-upload.html
The main requirement is file (the document itself) and token (upload voucher).
Then deploy the business code on the server to get the upload voucher, and obtain tokens via Wx.request request.
var = this; Wx.request ({ URL: ' Https://xxx/token ', method: ' POST ', data: {}, header: { ' content-type ': ' Application/x-www-form-urlencoded ' }, success:function (res) { That.token = res.data;//Returns a token by default, Assign to the already existing token attribute. Here is just an example, depending on the needs of the self-setting. }, fail:function (res) { Console.log (res) }})
Specifically how to deploy the seven cow Voucher code, can refer to Http://78re52.com1.z0.glb.cloudd ...%9c%8d%e5%8a%a1.pdf
After obtaining the voucher, you can upload it via wx.uploadfile. The specific code is:
var = this; var key = Math.random (). toString (+). substr (2); Generates a random string of filename wx.uploadfile ({ URL: ' https://up.qbox.me ', Filepath:flie, name: ' File ', formdata:{ ' token ': that.token,//just acquired the upload voucher ' key ': key//here is the file name for the upload after setting it , success:function (r) { var data = r.data;//Seven kn returns a JSON string containing the hash value and key if (typeof data=== ' string ') data = Json.parse (Data.trim ()); /unzip if (Data.key) { ...//Here you can use Data.key directly, the file has been uploaded successfully can be used. If it is a picture, it can be called directly from the image. }} , fail:function (res) { Console.log (res) } })
Finally, this way to solve the problem of Android cannot upload files, of course, upload their own server problem remains to be resolved.
However, there is a viable solution for developers who are in dire need of solutions.
Now using a third-party map source or storage source is a common scenario, many storage sources such as seven cattle, and the cloud, Vientiane map provides free space for developers to use.
We recommend that we also do more in this area of architecture and try.
Related recommendations:
Detailed POST request in small program development
Small program implementation drop-down loading and pull-up refresh detailed explanation