前端:

// 从相册选择3张图
                uni.chooseImage({
                    count: 3,
                    sizeType: ['original', 'compressed'],
                    sourceType: ['camera', 'album'],
                    success: function(res) {
                        console.log(res.tempFilePaths);
                        
                        if(that.imagesList.length<3)
                        {
                            for(var i=0;i<res.tempFilePaths.length;i++)
                            {
                                uni.uploadFile({
                                            url: that.httpBaseUrl+'APP/upload', //
                                            filePath: res.tempFilePaths[i],
                                            name: 'file',
                                            header: {
                                                "Content-Type": "multipart/form-data",
                                            },
                                            success: (uploadFileRes) => {
                                                let s = JSON.parse(uploadFileRes.data)
                                                console.log(uploadFileRes.data,s.data.code);
                                                if(s.data.code == 0)
                                                {
                                                    
                                                   
                                                }
                                                else
                                                {
                                                    uni.showToast({
                                                        title:'上传失败',
                                                        icon: 'none',
                                                        mask: true,
                                                    })
                                                }
                                            }
                                        });
                            }
                        }
                        else
                        {
                            uni.showToast({
                                icon:'error',
                                title:'最多三张图片'
                            })
                        }
                        
                        
                    }
                    });

 后端:

 public ActionResult upload(HttpPostedFile file)
        {
            //获取图片信息
            HttpPostedFileBase postfile = Request.Files["file"];
            //获取文件名
            string myFilName = postfile.FileName;
            postfile.SaveAs(Server.MapPath("~/APPUpl0adFile/") + myFilName);
            return Content(myFilName);
              
        }

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐