小程序
小游戏
企业微信
微信支付
扫描小程序码分享
为什么上传就一个图片呢 不能上个多图片呢?
13 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
@You can you up 官方API只有单个文件上传,并且最多并发10个
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
wxml是
<image src="{{src}}" controls ></image>
<view class="btn-area">
<button bindtap="bindButtonTap">上传图片</button>
</view>
?
@不忘初心@小糖糖
能给我发下不 万分感激 谢谢了!!!
@厚光 我也想知道 二楼不是说知道么
for循环 方法也是每次上传一次 多次上传而已 会有很多问题
文件地址支持数组就好了
upload:function(){
var that=this
wx.chooseImage({
count: 9,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: function (res) {
var tempFilePaths = res.tempFilePaths
console.log(tempFilePaths)
wx.uploadFile({
url: 'file_upload.php',
filePath: tempFilePaths[0],
name: 'file',
formData:{
'user': 'test'
},
success: function(res){
var data = res.data
wx.showModal({
title: '上传文件返回状态',
content: '成功',
success: function(res) {
if (res.confirm) {
console.log('用户点击确定')
}
})
const uploadTask = wx.uploadFile({
url: 'file_upload.php', //仅为示例,非真实的接口地址
name: 'files',
//do something
uploadTask.onProgressUpdate((res) => {
that.setData({
progress:res.progress
console.log('上传进度', res.progress)
console.log('已经上传的数据长度', res.totalBytesSent)
console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend)
uploadTask.abort() // 取消上传任务
fail:function(res){
console.log(res)
}),
path:tempFilePaths
@You can you up 你有更好的办法可以分享下.
不就是,chooseImage多个图片后,保存返回的多个图片地址。后面自己做批量上传
这for循环还是拉倒吧
success:
function
(res) {
for
(let index
in
res.tempFilePaths) {
that.uploadFile(res.tempFilePaths[index]).then(
(resolve) {
let thumbPath = that.data.thumbPath;
let thumb = that.data.thumb;
thumbPath.push(resolve);
thumb.push(app.baseUrl + resolve);
thumbPath: thumbPath,
thumb: thumb
});
(reject) {
console.log(reject);
wx.hideLoading();
@不忘初心 怎么做
正在加载...
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
@You can you up 官方API只有单个文件上传,并且最多并发10个
wxml是
<image src="{{src}}" controls ></image>
<view class="btn-area">
<button bindtap="bindButtonTap">上传图片</button>
</view>
</view>
?
@不忘初心@小糖糖
能给我发下不 万分感激 谢谢了!!!
@厚光 我也想知道 二楼不是说知道么
for循环 方法也是每次上传一次 多次上传而已 会有很多问题
文件地址支持数组就好了
upload:function(){
var that=this
wx.chooseImage({
count: 9,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: function (res) {
var tempFilePaths = res.tempFilePaths
console.log(tempFilePaths)
wx.uploadFile({
url: 'file_upload.php',
filePath: tempFilePaths[0],
name: 'file',
formData:{
'user': 'test'
},
success: function(res){
var data = res.data
wx.showModal({
title: '上传文件返回状态',
content: '成功',
success: function(res) {
if (res.confirm) {
console.log('用户点击确定')
}
}
})
const uploadTask = wx.uploadFile({
url: 'file_upload.php', //仅为示例,非真实的接口地址
filePath: tempFilePaths[0],
name: 'files',
formData:{
'user': 'test'
},
success: function(res){
var data = res.data
//do something
}
})
uploadTask.onProgressUpdate((res) => {
that.setData({
progress:res.progress
})
console.log('上传进度', res.progress)
console.log('已经上传的数据长度', res.totalBytesSent)
console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend)
})
uploadTask.abort() // 取消上传任务
},
fail:function(res){
console.log(res)
}
}),
that.setData({
path:tempFilePaths
})
}
})
},
@You can you up 你有更好的办法可以分享下.
不就是,chooseImage多个图片后,保存返回的多个图片地址。后面自己做批量上传
这for循环还是拉倒吧
wx.chooseImage({success:function(res) {for(let indexinres.tempFilePaths) {that.uploadFile(res.tempFilePaths[index]).then(function(resolve) {let thumbPath = that.data.thumbPath;let thumb = that.data.thumb;thumbPath.push(resolve);thumb.push(app.baseUrl + resolve);that.setData({thumbPath: thumbPath,thumb: thumb});},function(reject) {console.log(reject);})}wx.hideLoading();}})@不忘初心 怎么做