<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. 浏览器自动化的一些体会4 webBrowser控件之零碎问题2

    1. DocumentCompleted的多次执行问题 有的网页,会多次触发DocumentCompleted事件,由于它是异步的,不会阻塞,所以如果不恰当处理,会造成某些代码被错误地多次执行,造成意 ...

  2. PMI-ACP认证,你了解多少?

    PMI-ACP ®(敏捷管理专业人士)认证是由美国项目管理协会(PMI ®)于2011年推出的一门敏捷项目管理考试科目,全称Agile Certified Practitioner.PMI-ACP®证 ...

  3. 使用 gopacket 进行数据包捕获,注入和分析

    原文链接:https://www.devdungeon.com/content/packet-capture-injection-and-analysis-gopacket 接口文档:https:// ...

  4. zookeeper简单实现注册与发现以及其他基本操作

    添加依赖 <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookee ...

  5. WPF新手快速入门系列 1.布局

    [概要] 该系列文章主要描述,新手如何快速上手做wpf开发.看过网上部分的教程,主要讲述的是介绍控件.这并没有问题,但是没有把自己的使用经验也完整的描述出来. 所以特此编写此系列文章希望能帮助到,因为 ...

  6. 牛哄哄的celery

    一.什么是Celery 1.1.celery是什么 Celery是一个简单.灵活且可靠的,处理大量消息的分布式系统,专注于实时处理的异步任务队列,同时也支持任务调度. Celery的架构由三部分组成, ...

  7. Python爬虫 使用selenium处理动态网页

    对于静态网页,使用requests等库可以很方便的得到它的网页源码,然后提取出想要的信息.但是对于动态网页,情况就要复杂很多,这种页面的源码往往只有一个框架,其内容都是由JavaScript渲染出来的 ...

  8. Asterisk-WebRTC客户端的部署

    很久没有写博客了.最近完成asterisk 和  jssip的库集成,浏览器支持chrome/firefox.在集成的过程中遇到了一些问题,在这儿分享出来,免得大家走弯路. 在网上看一些帖子,环境都是 ...

  9. 浅谈 FTP、FTPS 与 SFTP

    无论是网盘还是云存储,上传都是一项很简单的操作.那些便捷好用的上传整理工具所用的 FTP 协议到底是什么意义,繁杂的模式又有何区别? 二狗子最近搭建了一个图片分享网站,每天都有好多人在他的网站上传许多 ...

  10. 【Android】Android开发可以手动进行控制的跑马灯效果,包括从左到右,以及从右到左,

    作者:程序员小冰,GitHub主页:https://github.com/QQ986945193 新浪微博:http://weibo.com/mcxiaobing 首先给大家看一下我们今天这个最终实现 ...