微信小程序文件上传结合lin ul
html <l-form name="goods" l-form-btn-class="l-form-btn-class" bind:linsubmit="submit"
>
<l-form-item label="商品分类:"rules="{{goods.goods_type}}" name="goods_type">
<l-input id="goods_type" hide-label show-row="{{false}}"/>
</l-form-item> <l-form-item label="商品属性:" roles="{{goods.goods_attr}}" name="goods_attr">
<l-input id="goods_attr" hide-label show-row="{{false}}"/>
</l-form-item> <l-form-item label="标题:" name="goods_name" roles="{{goods.goods_name}}">
<l-input id="goods_name" hide-label show-row="{{false}}"/>
</l-form-item> <l-form-item label="商品描述:" name="desc" roles="{{goods_name}}">
<l-textarea border="{{false}}" roles="{{desc}}" id="desc" value="{{desc}}" />
</l-form-item>
<l-image-picker size="4" bind:linchange="onChangeTap" />
<view slot="submit">
<l-button>提交</l-button>
<iew>
<view slot="reset">
<l-button type="default" plain>重置</l-button>
<view>
</l-form>
js
Page({
/**
* 页面的初始数据
*/
data: {
TimeID: -1,
goods_img:[],
goods:{
goods_type:{
required: true,
message: '分类不能为空',
trigger: 'change'
}
}
},
onChangeTap(e){
let that=this
let token=wx.getStorageSync('token')
e.detail.current.map(filePath=>{
wx.uploadFile({
filePath: filePath,
name: 'file',
// url: 'http://www.zy.com/api/upfile',
url: `${http}upfile`,
header:{token},
success:res=>{
let json=JSON.parse(res.data)
//文件追加数组
this.data.goods_img.push(json.data)
console.log(json.data);
}
})
})
},
submit(event){
console.log();
if (!event.detail.isValidate) {
return false
}
let desc=event.detail.desc
let goods_attr=event.detail.values.goods_attr
let goods_name=event.detail.values.goods_name
let goods_type=event.detail.values.goods_type
let goods_img=this.data.goods_img
let token=wx.getStorageSync('token')
wx.request({
url: `${http}goods`,
data:{desc,goods_attr,goods_name,goods_type,goods_img},
method:"POST",
header: {
'content-type': 'application/json', // 默认值
token
},
success:res=>{
console.log(res);
if (res.data.code == 200) {
wx.showToast({
title: '添加成功',
})
}else{
wx.showToast({
title: '添加失败',
})
}
},
fail:ret=>{
wx.showToast({
title: '系统错误',
})
}
})
},
laravel 控制器代码:
public function upload(Request $request)
{
DB::beginTransaction();
$file = $request->file('file');
// 百度云检测图片
$res=(new BaiDuCkeck())->imageAudit($file);
try {
$res=Oss::oss($file);
DB::commit();
// 返回上传之阿里云oss的图片链接
return ['code'=>200,'msg'=>'ok','data'=>$res];
}catch (\Exception $exception){
DB::rollBack();
return ['code'=>500,'msg'=>$exception->getMessage(),'data'=>[]];
}
效果图:

方式2 :简单实现
wxml
<l-form name="goods" l-form-btn-class="l-form-btn-class" bind:linsubmit="submit"
>
<view>
<l-image-picker size="4" bind:linchange="onChangeTap" />
</view>
<view slot="submit">
<l-button>提交</l-button>
</view>
</l-form>
wx.json
{
"usingComponents": {
"l-image-picker":"/miniprogram_npm/lin-ui/image-picker",
"l-form":"/miniprogram_npm/lin-ui/form"
}
}
wx.js
// liu ui 图片上传
onChangeTap(evt) {
evt.detail.current.map(filePath => {
wx.uploadFile({
filePath: filePath,
name: 'file',
url: 'http://www.yan.com/exam20/image',
header: {
'Content-Type': 'multipart/form-data'
},
success: res => { let json = JSON.parse(res.data)
//文件追加数组
this.data.goods_img.push(json.data) } }) }); }, submit(evt) {
// 获取到文件传输的值
let goods_img=this.data.goods_img
// 将值添加入库即可 },
laravel控制器:
/**
* 接受微信小程序端传过来的图片
*/
public function image(Request $request){
$imgUrl=$request->file('file')->getPathname();
// 验证图片链接
$res=BaiduService::imageCheck($imgUrl);
if ($res){
// 阿里云文件上传
$result=OssImageServerice::ossImage($imgUrl);
return response()->json(['code'=>200,'message'=>'文件检测结果合规,文件已经上传至阿里云服务器','data'=>$result]);
}else{
return response()->json(['code'=>500,'message'=>'文件不合规,上传失败','data'=>'']);
} }
微信小程序文件上传结合lin ul的更多相关文章
- 微信小程序文件上传至七牛云(laravel7)
1 wxml: <view> <form bindsubmit="dopost"> <view> <label>真实姓名</l ...
- 5行代码实现微信小程序图片上传与腾讯免费5G存储空间的使用
本文介绍了如何在微信小程序开发中使用腾讯官方提供的云开发功能快速实现图片的上传与存储,以及介绍云开发的 5G 存储空间的基本使用方法,这将大大提高微信小程序的开发效率,同时也是微信小程序系列教程的视频 ...
- 快速高效实现微信小程序图片上传与腾讯免费5G存储空间的使用
本文介绍了如何在微信小程序开发中使用腾讯官方提供的云开发功能快速实现图片的上传与存储,以及介绍云开发的 5G 存储空间的基本使用方法,这将大大提高微信小程序的开发效率 对于一般的图片上传功能开发,我们 ...
- 微信小程序图片上传并展示
1.首先编写微信小程序的页面和样式: index.js var total = []; Page({ data: { perImgSrc: [] }, onLoad: function (option ...
- 小程序文件上传uploadFile
前台代码: bindPhoto(e) { var that = this; wx.chooseImage({ count: 1, sizeType: ['original','compressed'] ...
- 微信小程序---图片上传+服务端接受
原文地址:http://blog.csdn.net/sk719887916/article/details/54312573 微信小程序,图片上传,应用地方-修改用户信息的头像. 详细代码: 小程序的 ...
- 微信小程序图片上传和裁剪
本篇博客用于解决微信小程序图片裁剪问题 图片裁剪常用于头像选择和图片合成等. 图片裁剪解决方案: 目前网络上知名的微信小程序图片裁剪插件是we-cropper(文末有链接) 操作步骤:下载好we-cr ...
- 微信小程序开发——上传代码片段到git仓库
微信开发者工具除了自带的git版本管理(本地服务)之外,还可以推送到在线git仓库中去,这样别人也可以通过git来拉取你的代码片段或小程序. 一.1.登录git 一.2.点击创建项目 一.3.填写项 ...
- 微信小程序代码上传,审核发布小程序
1.打开微信开发者工具 管理员扫码 -> 填写好小程序的项目目录.AppID(必须是客户已注册好的AppID).项目名称 2.在app.js中修改id(客户登录后台管理系统的id),app.js ...
随机推荐
- scanf用法及scanf中有\n的问题
scanf()函数的原理 想象输入设备(键盘)连接着一个叫"缓冲"的东西,把缓冲认为是一个字符数组. 当你的程序执行到scanf时,会从你的缓冲区读东西,如果缓冲区是空的,就阻塞住 ...
- VMware14安装windows7的详细过程
感谢大佬:https://blog.csdn.net/u012230668/article/details/81701893 一.安装VMware虚拟机,以及下载一份ghost win7系统 下载地址 ...
- winform 获得局域网内在线IP和计算机名,获取IP,多线程网络编程
转载请注明来源:https://www.cnblogs.com/hookjc/ using System; using System.Collections.Generic; using System ...
- php截取字符串,避免乱码
转载请注明来源:https://www.cnblogs.com/hookjc/ 1. 截取GB2312中文字符串 <?php//截取中文字符串 function mysubstr($str, $ ...
- 关于MPMoviePlayerController 缓存播放的一些技术准备
如果是视频文件,比如Mp4,avi,rmvb等可根据下面的这边文章推荐的Demo(http://code4app.com/ios/5292c381cb7e8445678b5ac2),经过测试可以进行同 ...
- H5架构和原生架构的区别
1.App的3种开发方式 表面上看,手机App都是同样的东西,就是手机上的应用程序,点击图标就能运行,但是它们的底层技术不一样.按照开发技术,App可以分成三大类.原生应用(简称nativeApp), ...
- appium填坑
首次使用appium web driver,不说搭建环境的麻烦,初次写完一个操作计算器的程序,但是运行一直报错:selenium.common.exceptions.WebDriverExceptio ...
- 用Express 创建项目
1.Node.js Express 框架安装:npm install express --save在当前目录下创建一个node_modules 2.安装必要的中间件npm install body-p ...
- PCI Verilog IP
1 PCI IP设计 虽然PCI已经逐渐淘汰,但是还是有不少应用需要这样的接口通讯. 设计目的是为了提供基于源码的PCI IP,这样硬件就不必受限于某一个FPGA型号,也方便ASIC迁移.由 ...
- Solution -「LOJ #150」挑战多项式 ||「模板」多项式全家桶
\(\mathcal{Description}\) Link. 给定 \(n\) 次多项式 \(F(x)\),在模 \(998244353\) 意义下求 \[G(x)\equiv\left\{ ...