图片上传云盘并显示
http://cdn.bi-ci.com/static/upyun-api/spark-md5.min.js
http://cdn.bi-ci.com/static/upyun-api/async.min.js
http://cdn.bi-ci.com/static/upyun-api/upyun-mu.js
var nowtimestamp = Date.parse(new Date());
//upload img
function autoUploadImg() {
filename = Math.random().toString(16).substring(2); // 随机字符串命名
var config = {
bucket: 'xingzhe-img',//upan命名空间
expiration: parseInt((new Date().getTime() + 3600000) / 1000),
form_api_secret: 'sdfskfhdjksfhkshdei',
};//upan配置
var instance = new Sand(config);
var options = {
'notify_url': 'http://upyun.com',
'allow-file-type': 'jpg,jpeg,png,gif',
'content-length-range': '1024,10240000', // 大小限制 1k-1M
'content-type': 'image/*',
};//upan options配置
instance.setOptions(options);
instance.upload('/rideNewsImg/' + nowtimestamp + '/' + filename);//上传图片
}
$('#file').change(function(){
autoUploadImg();
});
//get img src
document.addEventListener('uploaded', function(e) {
pic_url = 'http://static.imxingzhe.com' + e.detail.path;
$('#pic_url').attr('src','http://static.imxingzhe.com' + e.detail.path+'!avatar');
});
获取文件名:document.getElementById('file').files[0].name 获取文件后缀:document.getElementById('file').files[0].name.split('.').pop();