feat: upload-file

master
limin 2020-12-09 15:33:16 +08:00 committed by XuPeng
parent e73bf55356
commit 8009263549
5 changed files with 79 additions and 1 deletions

View File

@ -58,7 +58,8 @@
"pages/API/canvas/canvas",
"pages/API/get-wxml-node-info/get-wxml-node-info",
"pages/API/intersection-observer/intersection-observer",
"pages/API/download-file/download-file"
"pages/API/download-file/download-file",
"pages/API/upload-file/upload-file"
],
"window": {
"backgroundTextStyle": "light",

View File

@ -0,0 +1,29 @@
// pages/API/upload-file/upload-file.js
Page({
chooseImage() {
const self = this
wx.chooseImage({
success (res) {
const tempFilePaths = res.tempFilePaths
const files = res.tempFiles;
wx.uploadFile({
url: 'https://finchat-mop.finogeeks.club/api/v1/netDiskProxy/needCheckAuth/self?type=file&content={}&thumbnail=false&timestamp=1581254809&uuid=12345&appid=6000133&sign=21AE06173F566598FF9A055277AA55C4', //仅为示例,非真实的接口地址
filePath: tempFilePaths[0],
name: 'file',
formData: {
'uploadFile': files[0],
},
success (res){
const data = res.data
//do something
console.log(res);
},
fail (res) {
console.log(res);
}
})
}
})
},
})

View File

@ -0,0 +1,3 @@
{
"navigationBarTitleText": "上传文件"
}

View File

@ -0,0 +1,30 @@
<!--pages/API/upload-file/upload-file.wxml-->
<import src="../../common/head.wxml" />
<import src="../../common/foot.wxml" />
<view class="container">
<template is="head" data="{{title: 'uploadFile'}}"/>
<view class="page-body">
<view class="page-section">
<view class="page-body-info">
<block wx:if="{{imageSrc}}">
<image src="{{imageSrc}}" class="image" mode="aspectFit"></image>
</block>
<block wx:else>
<view class="image-plus image-plus-nb" bindtap="chooseImage">
<view class="image-plus-horizontal"></view>
<view class="image-plus-vertical"></view>
</view>
<view class="image-plus-text">选择图片</view>
</block>
</view>
</view>
</view>
<template is="foot" />
</view>

View File

@ -0,0 +1,15 @@
/* pages/API/upload-file/upload-file.wxss */
.image {
width: 100%;
height: 330px;
}
.page-body-info {
display: flex;
box-sizing: border-box;
padding: 15px;
height: 410px;
border-top: 1px solid var(--weui-FG-3);
border-bottom: 1px solid var(--weui-FG-3);
align-items: center;
justify-content: center;
}