[HTML] 纯文本查看 复制代码
/*my.js*/
\"user strict\";
var app = getApp();
Page({
data:{
// text:\"这是一个页面\"
uinfo:{},
source:'',
images:[]
},
// 上传图片
bindUploadHeader: function(){
var self = this;
wx.chooseImage({
count: 1, // 默认9
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function(res) {
var tempFilePaths = res.tempFilePaths
//及时预览
self.setData({
source:tempFilePaths[0]
})
wx.uploadFile({
url: 'http://www.kunyujie.com/myself/test/imageUpload?name=admin&passwd=admin',
filePath: tempFilePaths[0],
name: 'file',
header: {
\"Content-Type\": \"multipart/form-data\"
},
success:function(suc){
var data = JSON.parse(suc.data);
self.setData({
source:'http://www.kunyujie.com/myself/'+data.path
})
},
fail: function(err){
console.log(err)
},
complete:function(all){
//console.log(all)
}
})
}
})
},
// 上传图片
bindUploadHeader: function(){
var self = this;
wx.chooseImage({
count: 1, // 默认9
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function(res) {
var tempFilePaths = res.tempFilePaths;
var param ={
filePath:tempFilePaths[0],
name:'file',
formData:{}
};
app.api.imageUpload('test/imageUpload?name=admin&passwd=admin',param)
.then(function(res){
var res = JSON.parse(res);
self.setData({
source:app.uri+res.path
})
}).catch(function(err){
console.error(err)
})
//end
}
})
},
// 上传图片
bindUploadHeader: function(){
var self = this;
wx.chooseImage({
count: 2, // 默认9
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function(res) {
//批量图片上传
var imageArr = [], tempFilePaths = res.tempFilePaths;
for(var i=0,len=tempFilePaths.length; i