accessid = ''
accesskey = ''
host = ''
policyBase64 = ''
signature = ''
callbackbody = ''
filename = ''
key = ''
expire = 0
g_object_name = ''
g_object_name_type = ''
now = timestamp = Date.parse(new Date()) / 1000;
function send_request()
{
var xmlhttp = null;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp!=null)
{
if (sarry==""){
serverUrl = 'url?'+"order_id="+sid+"&"+"order_number="+snum;//单个
}else{
serverUrl = 'url'+"order_id="+sarry+"&"+"order_number="+snum;
}
//serverUrl = 'url?'+"order_id="+sid+"&"+"order_number="+snum;
xmlhttp.open( "GET", serverUrl, false );
xmlhttp.withCredentials = true;
xmlhttp.send(null);
return xmlhttp.responseText;
}
else
{
layer.msg("Your browser does not support XMLHTTP.",{icon:5});
}
};
function check_object_radio() {
var tt = document.getElementsByName('myradio');
for (var i = 0; i < tt.length ; i++ )
{
if(tt[i].checked)
{
g_object_name_type = tt[i].value;
break;
}
}
}
function get_signature()
{
//可以判断当前expire是否超过了当前时间,如果超过了当前时间,就重新取一下.3s 做为缓冲
now = timestamp = Date.parse(new Date()) / 1000;
if (expire < now + 3)
{
body = send_request()
var obj = eval ("(" + body + ")");
host = obj['host']
policyBase64 = obj['policy']
accessid = obj['accessid']
signature = obj['signature']
expire = parseInt(obj['expire'])
callbackbody = obj['callback']
key = obj['dir']
return true;
}
return false;
};
function random_string(len) {
len = len || 32;
var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
var maxPos = chars.length;
var pwd = '';
for (i = 0; i < len; i++) {
pwd += chars.charAt(Math.floor(Math.random() * maxPos));
}
return pwd;
}
function get_suffix(filename) {
pos = filename.lastIndexOf('.')
suffix = ''
if (pos != -1) {
suffix = filename.substring(pos)
}
return suffix;
}
function calculate_object_name(filename)
{
if (g_object_name_type == 'local_name')
{
g_object_name += "${filename}"
}
else if (g_object_name_type == 'random_name')
{
suffix = get_suffix(filename)
g_object_name = key + random_string(10) + suffix
}
return ''
}
function get_uploaded_object_name(filename)
{
if (g_object_name_type == 'local_name')
{
tmp_name = g_object_name
tmp_name = tmp_name.replace("${filename}", filename);
return tmp_name
}
else if(g_object_name_type == 'random_name')
{
return g_object_name
}
}
function set_upload_param(up, filename, ret)
{
if (ret == false)
{
ret = get_signature()
}
g_object_name = key;
if (filename != '') { suffix = get_suffix(filename)
calculate_object_name(filename)
}
new_multipart_params = {
'key' : g_object_name,
'policy': policyBase64,
'OSSAccessKeyId': accessid,
'success_action_status' : '200', //让服务端返回200,不然,默认会返回204
'callback' : callbackbody,
'signature': signature,
};
up.setOption({
'url': host,
'multipart_params': new_multipart_params
});
up.start();
}
var uploader = new plupload.Uploader({
runtimes : 'html5,flash,silverlight,html4',
browse_button : 'selectfiles',
//multi_selection: false,
container: document.getElementById('container'),
flash_swf_url : 'lib/plupload-2.1.2/js/Moxie.swf',
silverlight_xap_url : 'lib/plupload-2.1.2/js/Moxie.xap',
url : 'http://oss.aliyuncs.com',
multi_selection: 'false',//只能上传单个
unique_names:true,//生成唯一名
filters: {
mime_types : [
{ title : "Video files", extensions : "mp4,avi" }
],
max_file_size : '120mb', //最大只能上传10mb的文件
prevent_duplicates : false //true不允许选取重复文件
},
init: {
PostInit: function(files) {
document.getElementById('ossfile').innerHTML = '';
document.getElementById('postfiles').onclick = function() {
var input_video = document.getElementById("video");
// if(input_video.duration>120){//需要先判断选中的时常是否相等,取他的时常
if(setime==""){
if(input_video.duration>alltime){//多个上传得到的购买时常
layer.msg("您购买的时长为"+alltime+"s。"+"该视频的时长超过您所购买的投放时间,请重新选择视频",{icon:7,time:2000});
return false;
}
}else{
if(input_video.duration>setime){//单个上传得到的购买时常
layer.msg("您购买的时长为"+setime+"s。"+"该视频的时长超过您所购买的投放时间,请重新选择视频",{icon:7,time:2000});
return false;
}
}
var calc_video = (input_video.videoWidth/input_video.videoHeight).toString();
var videoc =(16/9).toString();
var videok =(4/3).toString();
if(calc_video != videoc && calc_video !=videok){
layer.msg("视频不是16:9的格式或者4/3的格式,不允许上传",{icon:7,time:2000});
return false;
}
set_upload_param(uploader, '', false);
uploader.start();
return false;
};
},
UploadFile:function(uploader,file){//当上传队列中某一个文件开始上传后触发,
},
FilesAdded: function(up, files) {
$.each(up.files, function (i, file) { //单个上传,替换文件
if (up.files.length <= 1) {
document.getElementById('ossfile').innerHTML = '';
return;
}
up.removeFile(file);
});
//有用
var input_video = document.getElementById("video");
var furl =URL.createObjectURL(files[0].getNative());
input_video.src=furl;
plupload.each(files, function(file) {
document.getElementById('ossfile').innerHTML += '<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ')<b></b>'
+'<div class="progress"><div class="progress-bar" style="width: 0%"></div></div>'
+'</div>';
});
},
BeforeUpload: function(up, file) {
check_object_radio();
set_upload_param(up, file.name, true);
},
UploadProgress: function(up, file) {
var d = document.getElementById(file.id);
d.getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
var prog = d.getElementsByTagName('div')[0];
var progBar = prog.getElementsByTagName('div')[0]
progBar.style.width= 2*file.percent+'px';
progBar.setAttribute('aria-valuenow', file.percent);
},
FileUploaded: function(up, file, info) {
if (info.status == 200)
{
var result = eval('('+info.response+')');
if(result.status=="success"){
layer.msg(result.message,{icon:6,time:2000},function(){
parent.layer.close(index);
var pac = window.parent.document.getElementById('bindclick');
pac.click();
});
}
if(result.status=="fail"){
layer.msg(result.message,{icon:5,time:2000},function(){
parent.layer.close(index);
var pac = window.parent.document.getElementById('bindclick');
pac.click();
})
}
}
else if (info.status == 203)
{
// document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '上传到OSS成功,但是oss访问用户设置的上传回调服务器失败,失败原因是:' + info.response;
}
else
{
// document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = info.response;
}
},
Error: function(up, err) {
if (err.code == -600) {
// document.getElementById('console').appendChild(document.createTextNode("\n选择的文件太大了,可以根据应用情况,在upload.js 设置一下上传的最大大小"));
layer.msg('选择的文件太大了',{icon:7},{time:2000});
return;
}
else if (err.code == -601) {
// document.getElementById('console').appendChild(document.createTextNode("\n选择的文件后缀不对,可以根据应用情况,在upload.js进行设置可允许的上传文件类型"));
layer.msg('请选择正确的视频文件',{icon:7},{time:2000});
return;
}
else if (err.code == -602) {
//document.getElementById('console').appendChild(document.createTextNode("\n这个文件已经上传过一遍了"));
layer.msg('这个文件已经上传过一遍了',{icon:7},{time:2000});
return;
}
else
{
// document.getElementById('console').appendChild(document.createTextNode("\nError xml:" + err.response));
layer.msg(err.response,{icon:7},{time:2000});
return;
}
}
}
});
uploader.init();
附:gif效果 http://www.cnblogs.com/zhixiaoxiao/gallery/image/200811.html
- ASP.NET Core的身份认证框架IdentityServer4--(5)自定义用户登录(使用官网提供的UI)
IdentityServer官方提供web页面,可以根据需求修改样式.具体UI下载跟配置参考官网文档. 文档地址:https://identityserver4.readthedocs.io/en/r ...
- OSS阿里云上传文件 前端js下载url跨域问题
场景: 1.后端上传文件至阿里云OSS,返回得到一个URL. 2.前端用这个URL下载文件,ajax请求异常:No 'Access-Control-Allow-Origin' header is pr ...
- SpringBoot官网提供所有组件整理
下面所有SpringBoot组件整理来自于:https://start.spring.io/,紧随Spring社区的步伐...... Developer Tools Spring Boot DevTo ...
- Android 官网提供的Custom-view 编译出错--error: No resource identifier found for attribute
error: No resource identifier found for attribute in custom-views from http://developer.android.com ...
- php阿里云oss文件上传
php的文件上传 文件上传 php的文件上传放在了$_FILES数组里,单文件和多文件上传的区别在于$_FILES['userfile']['name']是否为数组, 不熟悉的可以读一下官方文档 单文 ...
- C# .net Ueditor实现图片上传到阿里云OSS 对象存储
在学习的时候,项目中需要实现在Ueditor编辑器中将图片上传到云储存中,老师演示的是上传到又拍云存储,既然看了一遍,直接照搬不算本事,咱们可以依葫芦画瓢自己来动手玩玩其它的云存储服务. 现在云计算产 ...
- 记一次阿里云oss文件上传服务假死
引言 记得以前刚开始学习web项目的时候,经常涉及到需要上传图片啥的,那时候都是把图片上传到当前项目文件夹下面,每次项目一重启图片就丢了.虽然可以通过修改/tomcat/conf/server.xml ...
- 保姆级SpringBoot+Vue图片上传到阿里云OSS教程
小二是新来的实习生,作为技术 leader,我给他安排了一个非常简单的练手任务,把前端 markdown 编辑器里上传的图片保存到服务器端,结果他真的就把图片直接保存到了服务器上,这下可把我气坏了,就 ...
- 在OneThink(ThinkPHP3.2.3)中整合阿里云OSS的PHP-SDK2.0.4,实现Web端直传,服务端签名直传并设置上传回调的实现流程
在OneThink(ThinkPHP3.2.3)中整合阿里云OSS的PHP-SDK2.0.4,实现本地文件上传流程 by shuijingwan · 2016/01/13 1.SDK安装 github ...
随机推荐
- Python 基础 3 - 元组
元组与列表区别 Python 元组与列表类似,不同之处在于列表可以修改,元组不可以修改 元组用小括号 () 定义,列表用方括号 [] 定义 元组不可修改,列表可修改 元组创建 只需要在小括号 () 内 ...
- Linux下Eclipse以及Java环境安装教程[小白化](2019-9)
Linux下安装Eclipse以及Java 一.前言 许久未用Eclipse, Ubuntu上也没装Eclipse, 今天安装发现, 好多东西都忘了. 不过经过一番查找(百度, csdn) 终于还是安 ...
- jmeter linux压测报错:Error in NonGUIDriver java.lang.IllegalArgumentException: Problem loading XML from:'/home/server/ptest/disk_out.jmx'.
1.linux环境jmeter与win环境编写脚本的jmeter版本不一致,版本改为一致 2.脚本中存在中文,去除中文 3.脚本中存在类似于jp@gc - Active Threads Over Ti ...
- 【C/C++】qsort函数的使用方法和细节
函数概述 qsort 为quick_sort的简写,意为快速排序,主要用于对各种数组的排序. 因为数组的元素可能是任何类型的,甚至是结构或者联合,所以必须高数函数qsort如何确定两个数组元素哪一个& ...
- 50 (OC)* URL Scheme 网页地址协议
在Xcode 9 下,新建的工程,在plist文件中注册URL Schemes,从safari无法打开问题 1:URL Scheme是什么 2:URL Scheme有什么作用 3:URL Scheme ...
- RDD基本操作之Action
Action介绍 在RDD上计算出来一个结果 把结果返回给driver program或保存在文件系统,count(),save 常用的Action reduce() 接收一个函数,作用在RDD两个类 ...
- 自定义 Alamofire 的 response serializer
Alamofire 的 DataRequest 类针对二进制数据.字符串.json.属性列表提供了一系列方便解析的方法(内部实际上使用的是 Response Serializer),现在我们要针对服务 ...
- Django模板语言, 过滤器整理
Django模板语言,过滤器整理 1. add {{ value|add:"2" }} 把add后的参数加给value: 处理时,过滤器首先会强制把两个值转换成Int类型. 如果强 ...
- 用 CocosCreator 快速开发推箱子游戏
游戏总共分为4个功能模块: - 开始游戏(menuLayer) - 关卡选择(levelLayer) - 游戏(gameLayer) - 游戏结算(gameOverLayer) Creator内组件效 ...
- hadoop之mapreduce详解(进阶篇)
上篇文章hadoop之mapreduce详解(基础篇)我们了解了mapreduce的执行过程和shuffle过程,本篇文章主要从mapreduce的组件和输入输出方面进行阐述. 一.mapreduce ...