小程式單圖上傳到伺服器
阿新 • • 發佈:2018-11-14
// 上傳營業執照
fail_yingye(e) {
var that = this;
var uniacid = app.siteInfo.uniacid;
var idx = e.currentTarget.dataset.index;
var yingye = that.data.yingye;
var openid = wx.getStorageSync('openid')
wx.chooseImage({
count: 1, // 預設9
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: function (res) {
var yingyes = that.data.yingye;
var tempFilePath = res.tempFilePaths[0];
yingyes[idx].src = tempFilePath;
wx.uploadFile({
url: that.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=Upload&m=pinba',
filePath: tempFilePath,
name: 'upfile',
formData: {
// 'path': 'wxchat'
},
success: function (res) {
console.log(res.data)
that.setData({
yingyes: res.data,
})
// app.util.request({
// 'url': 'entry/wxapp/Shenhe',
// data: {
// openid: openid,
// uplogo: res.data
// },
// success: function (res) {
// console.log(res.data.data)
// // that.setData({
// // myxiaofeisum: res.data.data
// // })
// },
// fail: function (err) {
// console.log(err)
// },
// }) }, fail: function (res) { console.log(res) }, }) that.setData({ yingye: yingyes }) console.log(yingye) }, fail: function (res) { } }) }, url獲取 app.util.request({ 'url': 'entry/wxapp/url', 'cachetime': '0', success: function (res) { console.log(res) that.setData({ url: res.data }) }, })
<!--上傳營業執照 -->
<view class='yingye sj_name'>
<view class='font28 color_666'>上傳營業執照</view>
<view class='yingye_img' wx:for="{{yingye}}" wx:key="yy">
<image src='{{item.src}}' data-index='{{index}}' bindtap='fail_yingye'></image>
<view class='font26 color_666 txt_center'>{{item.txt}}</view>
</view>
</view>
// }) }, fail: function (res) { console.log(res) }, }) that.setData({ yingye: yingyes }) console.log(yingye) }, fail: function (res) { } }) }, url獲取 app.util.request({ 'url': 'entry/wxapp/url', 'cachetime': '0', success: function (res) { console.log(res) that.setData({ url: res.data }) }, })