1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <template>
- <!-- #ifdef APP -->
- <scroll-view class="page-scroll-view">
- <!-- #endif -->
- <view>
- <page-head :title="title"></page-head>
- <view class="uni-padding-wrap uni-common-mt">
- <view class="uni-btn-v uni-common-mt">
- <button type="primary" @click="uploadFile">选择文件上传</button>
- <button type="primary" @click="chooseAndUploadFile">一个接口选择文件并上传</button>
- </view>
- </view>
- </view>
- <!-- #ifdef APP -->
- </scroll-view>
- <!-- #endif -->
- </template>
- <script>
- export default {
- data() {
- return {
- title: '云存储'
- }
- },
- onLoad() {
- },
- onUnload() {
- },
- methods: {
- uploadFile: function () {
- uni.chooseImage({
- count: 1,
- success(res) : void {
- uni.showLoading({
- title: '上传中...'
- })
- const tempFilePath = res.tempFilePaths[0]
- uniCloud.uploadFile({
- filePath: tempFilePath,
- cloudPath: 'test.jpg'
- })
- .then(function (res) {
- uni.hideLoading()
- console.log(res)
- uni.showModal({
- content: '上传成功',
- showCancel: false
- });
- })
- .catch(function (err : any | null) {
- uni.hideLoading()
- const error = err as UniCloudError
- uni.showModal({
- content: '上传失败,' + error.errMsg,
- showCancel: false
- });
- })
- // .finally((_: number) : void => {
- // uni.hideLoading()
- // })
- },
- fail(err) : void {
- console.error('chooseImage fail: ', err)
- }
- })
- },
- chooseAndUploadFile() {
- uniCloud.chooseAndUploadFile({
- type: 'image'
- }).then(function (res) {
- uni.hideLoading()
- console.log(res)
- uni.showModal({
- content: '上传成功',
- showCancel: false
- });
- })
- .catch(function (err : any | null) {
- uni.hideLoading()
- const error = err as UniCloudError
- uni.showModal({
- content: '上传失败,' + error.errMsg,
- showCancel: false
- });
- })
- }
- }
- }
- </script>
- <style>
- </style>
|