<template>
<div id="container">
<div class="img-item m-1 upload-file" id="selectfiles" @click="axioSignal">
<span class="mask"></span>
<b-form-file multiple accept="image/*"></b-form-file>
</div>
</div>
</template> <script>
import plupload from 'plupload' export default {
name: 'formImg',
data () {
return {
signal: {
policyBase64: '',
accessid: '',
signature: ''
},
imgs: [],
imgUrl: [],
uploader: {}
}
},
mounted () {
let _this = this
this.uploader = new plupload.Uploader({
runtimes: 'html5,flash,silverlight,html4',
browse_button: 'selectfiles',
container: document.getElementById('container'), init: {
PostInit: function () {
console.log(`PostInit`)
// _this.axioSignal()
// console.log(_this.onImgs)
// _this.imgs.push(_this.onImgs)
// _this.imgs = _this.onImgs
// console.log(_this.onImgs)
// console.log(_this.imgs)
}, FilesAdded: function (up, files) {
_this.uploader.start()
// plupload.each(files, function (file) {
console.log(`FilesAdded`)
// })
}, BeforeUpload: function (up, file) {
_this.set_upload_param(up, file.name, true)
}, // UploadProgress: function (up, file) {
// console.log(`UploadProgress`)
// }, FileUploaded: function (up, file, info) {
console.log(`FileUploaded`)
if (info.status === 200) {
_this.imgUrl.forEach(item => {
_this.imgs.push(item)
_this.imgUrl = []
})
_this.$emit('imgs', _this.imgs)
}
} // Error: function (up, err) {
// document.getElementById('console').appendChild(document.createTextNode('\nError xml:' + err.response))
// }
}
})
// _this.uploader.addFileFilter('max_file_size', function (maxSize, file, cb) {
// var undef
//
// maxSize = plupload.parseSize(maxSize)
//
// // Invalid file size
// if (file.size !== undef && maxSize && file.size > maxSize) {
// this.trigger('Error', {
// code: plupload.FILE_SIZE_ERROR,
// message: plupload.translate('File size error.'),
// file: file
// })
// cb(false)
// } else {
// cb(true)
// }
// })
_this.uploader.init()
},
methods: {
axioSignal () {
console.log(`axioSignal`)
this.$axios({
method: 'get',
url: 'http://www.lyly360.com/fs/ali/signal'
}).then(res => {
this.signal.policyBase64 = res.policy
this.signal.accessid = res.accessid
this.signal.signature = res.signature
this.signal.host = res.host
})
},
formatNames (files) {
console.log(`formatNames`)
if (files.length === 1) {
return files[0].name
} else {
return `${files.length} files selected`
}
},
// postfiles () {
// this.uploader.start()
// },
random_string (len) {
len = len || 32
var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'
var maxPos = chars.length
var pwd = ''
for (var i = 0; i < len; i++) {
pwd += chars.charAt(Math.floor(Math.random() * maxPos))
}
return pwd
}, get_suffix (filename) {
var pos = filename.lastIndexOf('.')
var suffix = ''
if (pos !== -1) {
suffix = filename.substring(pos)
}
return suffix
}, calculate_object_name (filename) {
var suffix = this.get_suffix(filename)
var randName = this.random_string(10) + suffix
return randName
}, set_upload_param (up, filename) {
var randFileName = 'file' + this.calculate_object_name(filename)
this.imgUrl.push(this.signal.host + '/' + randFileName + '-ly.jpg')
var newMparams = {
'key': randFileName,
'policy': this.signal.policyBase64,
'OSSAccessKeyId': this.signal.accessid,
'success_action_status': '200',
'signature': this.signal.signature
} up.setOption({
'url': this.signal.host,
'multipart_params': newMparams
})
}
}
}
</script> <style lang="stylus" scoped>
.upload-file {
height: 100px;
width: 100px;
vertical-align: middle;
text-align: center;
line-height: 100px;
}
.upload-file .custom-file {
height: 100px;
width: 100px;
opacity: 0;
}
>>>.upload-file .custom-file input {
height: 80%;
width: 80%;
overflow hidden
}
.mask {
position: absolute;
width: 100%;
height: 100%;
background-image: url(../assets/upload.png);
background-size: 100px 100px;
background-position: center center
left: 0;
top: 0;
} </style>

前端直传文件到aliyun OSS的更多相关文章

  1. Aliyun Oss 上传文件

    目录 Aliyun OSS OSS 简介 OSS 基本概念 OSS 功能概述 OSS 使用 创建存储空间Bucket 创建子目录 Java编码 测试 Aliyun OSS OSS 简介 阿里云对象存储 ...

  2. 直传文件到Azure Storage的Blob服务中

    (此文章同时发表在本人微信公众号“dotNET每日精华文章”,欢迎右边二维码来关注.) 题记:为了庆祝获得微信公众号赞赏功能,忙里抽闲分享一下最近工作的一点心得:如何直接从浏览器中上传文件到Azure ...

  3. Windows下编译使用Aliyun OSS PHP SDK

    摘要: WIN环境下搭建Aliyun OSS PHP SDK编译运行环境.从PHP的安装逐步完成,SDK的编译运行.即使没有任何PHP基础,也能顺利完成. 安装环境:Win7 64 + PHP 5.6 ...

  4. aliyun oss操作汇总

    // endpoint以杭州为例,其它region请按实际情况填写 String endpoint = "http://oss-cn-hangzhou.aliyuncs.com"; ...

  5. vue 上传图片到阿里云(前端直传:不推荐)

    为何要这样做:减轻后端数据库压力(个人觉得于前端没啥用,谁返回来都行) 代码部分: <template> <div class="upLoad"> < ...

  6. HTML5 File API — 让前端操作文件变的可能

    前言 在 HTML5 File API 出现之前,前端对于文件的操作是非常有局限性的,大多需要配合后端实现.出于安全角度考虑,从本地上传文件时,代码不可能获取文件在用户本地的地址,所以纯前端不可能完成 ...

  7. 前端js文件合并三种方式

    最近在思考前端js文件该如何合并,当然不包括不能合并文件,而是我们能合并的文件,想了想应该也只有三种方式. 三个方式如下: 1. 一个大文件,所有js合并成一个大文件,所有页面都引用它. 2. 各个页 ...

  8. Aliyun OSS SDK 异步分块上传导致应用异常退出

    问题描述: 使用Aliyun OSS SDK的BeginUploadPart/EndUploadPart执行异步分块上传操作,程序出现错误并异常退出! 原因分析: Using .NET Framewo ...

  9. js前端读写文件的方法(json、excel)

    1.前端读取文件的实现 关键:利用文件上传对话框预览本地文件.利用FileReader读取文件 前端预览本地文件 <input tabindex="-1" id=" ...

随机推荐

  1. Istio Routing 实践掌握virtualservice/gateway/destinationrule/AB版本发布/金丝雀发布

    原文 在学习像 Istio 这样的新技术时,看一下示例应用程序总是一个好主意. Istio repo 有一些示例应用程序,但它们似乎有各种不足. 文档中的 BookInfo 是一个很好的示例. 但是, ...

  2. Linux文件权限-笔记

    文件权限共10个字符,第一个字符表示该文件是[文件夹]或[文件]——如果是字符“d"则表示该文件是文件夹:如果是字符“-”则表示是文件. 后九个字符,三个一组,共三组,分别表示[所有者权限] ...

  3. eclipse项目文件夹整理

    1.点击倒三角 2.系统默认为Projects,选择第二个working sets 3.点击Configure Working Sets,点new 4.点击后,选中点Add 5.添加一个名字,Fins ...

  4. JDBC驱动程序分类

    JDBC驱动程序分类 JDBC驱动程序:各个数据库厂商根据JDBC的规范制作的 JDBC 实现类的类库 JDBC驱动程序总共有四种类型: 第一类:JDBC-ODBC桥. 第二类:部分本地API部分Ja ...

  5. Python开发的入门教程(二)-List和Tuple类型

    介绍 本文主要介绍Python中List和Tuple类型的基本知识和使用. Python创建list Python内置的一种数据类型是列表:list.list是一种有序的集合,可以随时添加和删除其中的 ...

  6. 2020.5.26 第六篇 Scrum冲刺博客

    Team:银河超级无敌舰队 Project:招新通 项目冲刺集合贴:链接 目录 一.每日站立会议 1.1 会议照片 1.2 项目完成情况 二.项目燃尽图 三.签入记录 3.1 代码/文档签入记录 3. ...

  7. vmd与ovito的对比

    1.minimize后,lammps生成的data文件 2.pdb:

  8. OI常用数学定理&方法总结

    组合数计算($O(n)$) https://www.cnblogs.com/linzhuohang/p/11548813.html Lucas定理 如果要计算很大的组合数,但模数较小,考虑这个方法 对 ...

  9. iOS多线程之GCD、OperationQueue 对比和实践记录

    [toc] 简介      在计算的早期,计算机可以执行的最大工作量是由 CPU 的时钟速度决定的.但是随着技术的进步和处理器设计的紧凑化,热量和其他物理约束开始限制处理器的最大时钟速度.因此,芯片制 ...

  10. 【转】Echarts自适应

    var myChart1 = echarts.init(document.getElementById('chart1')); var option = myChart1.getOption(); w ...