微信小程序图片怎么上传(微信小程序图片上传)
微信小程序图片怎么上传,原文标题:微信小程序上传图片功能实现。微信小程序上传图片功能,后台asp.net2020
微信小程序图片怎么上传,原文标题:微信小程序上传图片功能实现。
微信小程序上传图片功能,后台asp.net
2020.09.11优化了部分功能
JS:
// 删除图片
clearImg:function(e){
var nowList = [];//新数据
var uploaderList = this.data.uploaderList;//原数据
for (let i = 0; i < uploaderList.length;i ){
if (i == e.currentTarget.dataset.index){
continue;
}else{
nowList.push(uploaderList[i])
}
}
this.setData({
uploaderNum: this.data.uploaderNum – 1,
uploaderList: nowList,
showUpload: true
})
},
//展示图片
showImg:function(e){
var that=this;
wx.previewImage({
urls: that.data.uploaderList,
current: that.data.uploaderList[e.currentTarget.dataset.index]
})
},
//选择图片
upload: function(e) {
var that = this;
wx.chooseImage({
count: 3 – that.data.uploaderNum, // 默认9
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function(res) {
// console.log(res)
// 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
let tempFilePaths = res.tempFilePaths;
let uploaderList = that.data.uploaderList.concat(tempFilePaths);
if (uploaderList.length>=3){
that.setData({
showUpload:false
})
}
that.setData({
uploaderList: uploaderList,
uploaderNum: uploaderList.length,
})
}
})
},
//上传图片并更新DB
uploadImg: function (openid) {
var that = this;
//上传图片
for (var index in this.data.uploaderList) {
console.log(this.data.uploaderList);
wx.uploadFile({
url: 'https://域名:端口/Repair.aspx',
filePath: that.data.uploaderList[index],
name: 'uploadfile',
header: {
'content-type': 'multipart/form-data'
}, // 设置请求的 header
formData: {
'openid': openid
}, // HTTP 请求中其他额外的 form data
success: function (res) {
console.log(res.data)
},
fail: function (res) {
// console.info(res)
}
})
}
},
后台asp.net
public void UploadFile()
{
HttpPostedFile file = Request.Files["uploadfile"];
if (file != null)
{
try
{
string extName = System.IO.Path.GetExtension(file.FileName);
if (extName != ".jpeg" && extName != ".gif" && extName != ".jpg" && extName != ".png")
{
Response.Write("文件格式不合法!");
return;
}
string uploadImgName = "/Upload/" Guid.NewGuid().ToString() file.FileName;
file.SaveAs(Request.MapPath(uploadImgName));
Response.Write("上传成功!");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
else
{
Response.Write("null");
}
}

随机文章
SEO小小课堂网SEO教程
友情链接交换
网站内容优化
GEO培训
SEO小小课堂网
SEO教程
站长导航
百度搜索“网赚联盟”即可找到本站,微信搜索“小小课堂网”关注小小课堂网公众号。网赚联盟( wangzhuan.org.cn )欢迎用户投稿,发布者:退役程序猿,文章版权归作者所有,投稿文章不代表网赚联盟立场,中二少年发布为网赚联盟原创文章,转载请注明出处:https://wangzhuan.org.cn/339161.html

微信扫一扫
支付宝扫一扫