首页 文章 精选 留言 我的

精选列表

搜索[端侧AI],共10000篇文章
优秀的个人博客,低调大师

阿里云 oss JavaScript客户端签名文件上传 vue2.0

官方文档地址https://help.aliyun.com/document_detail/31925.html?spm=5176.doc31923.6.631.SAJk7p 官方文档内给的demo是传统的代码引入方式,用到的模块有crypto、hmac、sha1、base64、plupload。这些模块都是定制化的,用npm安装指定的模块会出现相应的方法找不到未定义情况,所以想在vue2.0项目中使用oss上传,需要自己定义一个crypto方法,把hmac、sha1方法放到crypto对象中,base64方法是独立的,直接把demo中的文件放入项目中,用export default dao's'hvar base64map = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' var Crypto = {} var util = Crypto.util = { // Bit-wise rotate left rotl: function (n, b) { return (n << b) | (n >>> (32 - b)) }, // Bit-wise rotate right rotr: function (n, b) { return (n << (32 - b)) | (n >>> b) }, // Swap big-endian to little-endian and vice versa endian: function (n) { // If number given, swap endian if (n.constructor === Number) { return util.rotl(n, 8) & 0x00FF00FF | util.rotl(n, 24) & 0xFF00FF00 } // Else, assume array and swap all items for (var i = 0; i < n.length; i++) { n[i] = util.endian(n[i]) } return n }, // Generate an array of any length of random bytes randomBytes: function (n) { for (var bytes = []; n > 0; n--) { bytes.push(Math.floor(Math.random() * 256)) } return bytes }, // Convert a string to a byte array stringToBytes: function (str) { var bytes = [] for (var i = 0; i < str.length; i++) { bytes.push(str.charCodeAt(i)) } return bytes }, // Convert a byte array to a string bytesToString: function (bytes) { var str = [] for (var i = 0; i < bytes.length; i++) { str.push(String.fromCharCode(bytes[i])) } return str.join('') }, // Convert a string to big-endian 32-bit words stringToWords: function (str) { var words = [] for (var c = 0, b = 0; c < str.length; c++, b += 8) { words[b >>> 5] |= str.charCodeAt(c) << (24 - b % 32) } return words }, // Convert a byte array to big-endian 32-bits words bytesToWords: function (bytes) { var words = [] for (var i = 0, b = 0; i < bytes.length; i++, b += 8) { words[b >>> 5] |= bytes[i] << (24 - b % 32) } return words }, // Convert big-endian 32-bit words to a byte array wordsToBytes: function (words) { var bytes = [] for (var b = 0; b < words.length * 32; b += 8) { bytes.push((words[b >>> 5] >>> (24 - b % 32)) & 0xFF) } return bytes }, // Convert a byte array to a hex string bytesToHex: function (bytes) { var hex = [] for (var i = 0; i < bytes.length; i++) { hex.push((bytes[i] >>> 4).toString(16)) hex.push((bytes[i] & 0xF).toString(16)) } return hex.join('') }, // Convert a hex string to a byte array hexToBytes: function (hex) { var bytes = [] for (var c = 0; c < hex.length; c += 2) { bytes.push(parseInt(hex.substr(c, 2), 16)) } return bytes }, // Convert a byte array to a base-64 string bytesToBase64: function (bytes) { // Use browser-native function if it exists if (typeof btoa === 'function') return btoa(util.bytesToString(bytes)) var base64 = [] var overflow for (var i = 0; i < bytes.length; i++) { switch (i % 3) { case 0: base64.push(base64map.charAt(bytes[i] >>> 2)) overflow = (bytes[i] & 0x3) << 4 break case 1: base64.push(base64map.charAt(overflow | (bytes[i] >>> 4))) overflow = (bytes[i] & 0xF) << 2 break case 2: base64.push(base64map.charAt(overflow | (bytes[i] >>> 6))) base64.push(base64map.charAt(bytes[i] & 0x3F)) overflow = -1 } } // Encode overflow bits, if there are any if (overflow !== undefined && overflow !== -1) { base64.push(base64map.charAt(overflow)) } // Add padding while (base64.length % 4 !== 0) base64.push('=') return base64.join('') }, // Convert a base-64 string to a byte array base64ToBytes: function (base64) { // Use browser-native function if it exists if (typeof atob === 'function') return util.stringToBytes(atob(base64)) // Remove non-base-64 characters base64 = base64.replace(/[^A-Z0-9+/]/ig, '') var bytes = [] for (var i = 0; i < base64.length; i++) { switch (i % 4) { case 1: bytes.push((base64map.indexOf(base64.charAt(i - 1)) << 2) | (base64map.indexOf(base64.charAt(i)) >>> 4)) break case 2: bytes.push(((base64map.indexOf(base64.charAt(i - 1)) & 0xF) << 4) | (base64map.indexOf(base64.charAt(i)) >>> 2)) break case 3: bytes.push(((base64map.indexOf(base64.charAt(i - 1)) & 0x3) << 6) | (base64map.indexOf(base64.charAt(i)))) break } } return bytes } } Crypto.HMAC = function (hasher, message, key, options) { key = key.length > hasher._blocksize * 4 ? hasher(key, { asBytes: true }) : util.stringToBytes(key) // XOR keys with pad constants var okey = key var ikey = key.slice(0) for (var i = 0; i < hasher._blocksize * 4; i++) { okey[i] ^= 0x5C ikey[i] ^= 0x36 } var hmacbytes = hasher(util.bytesToString(okey) + hasher(util.bytesToString(ikey) + message, { asString: true }), { asBytes: true }) return options && options.asBytes ? hmacbytes : options && options.asString ? util.bytesToString(hmacbytes) : util.bytesToHex(hmacbytes) } var SHA1 = Crypto.SHA1 = function (message, options) { var digestbytes = util.wordsToBytes(SHA1._sha1(message)) return options && options.asBytes ? digestbytes : options && options.asString ? util.bytesToString(digestbytes) : util.bytesToHex(digestbytes) } SHA1._sha1 = function (message) { var m = util.stringToWords(message) var l = message.length * 8 var w = [] var H0 = 1732584193 var H1 = -271733879 var H2 = -1732584194 var H3 = 271733878 var H4 = -1009589776 // Padding m[l >> 5] |= 0x80 << (24 - l % 32) m[((l + 64 >>> 9) << 4) + 15] = l for (var i = 0; i < m.length; i += 16) { var a = H0 var b = H1 var c = H2 var d = H3 var e = H4 for (var j = 0; j < 80; j++) { if (j < 16) { w[j] = m[i + j] } else { var n = w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16] w[j] = (n << 1) | (n >>> 31) } var t = ((H0 << 5) | (H0 >>> 27)) + H4 + (w[j] >>> 0) + (j < 20 ? (H1 & H2 | ~H1 & H3) + 1518500249 : j < 40 ? (H1 ^ H2 ^ H3) + 1859775393 : j < 60 ? (H1 & H2 | H1 & H3 | H2 & H3) - 1894007588 : (H1 ^ H2 ^ H3) - 899497514) H4 = H3 H3 = H2 H2 = (H1 << 30) | (H1 >>> 2) H1 = H0 H0 = t } H0 += a H1 += b H2 += c H3 += d H4 += e } return [H0, H1, H2, H3, H4] } // Package private blocksize SHA1._blocksize = 16 export default Crypto 以上是crypto方法,这里需要注意的是,如果vue项目中用到了代码校验,这里的代码会有语法报错,仔细改掉就可以了 plupload模块直接用npm安装就好了,相应文档地址http://www.phpin.net/tools/plupload/ 接下来就可以按照官方demo 进行相应的修改,配置自己的参数,进行上传测试

优秀的个人博客,低调大师

移动端图片上传方法【更好的兼容安卓IOS和微信】

之前的移动端上传的方法,有些朋友测试说微信支持不是很好,还有部分安卓机也不支持,其实我已经有了另一个方法,但是例子还没整理出来,而联系我的很多朋友需要,所以就提前先发出来了,并且做一个简单的说明,就不做一个demo了。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 <!doctypehtml> < html > < head > < meta charset = "utf-8" > < meta name = "viewport" content = "width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0" > < title >图片压缩</ title > < style > body{margin:0;padding:0;} html{font-size:62.5%;} .imgzip{padding:1em;} .imgzip.itm{padding-bottom:1em;word-break:break-all;font-size:1.2rem;line-height:1.5em;} .imgzip.itm.tit{margin-bottom:.5em;background-color:#e71446;color:#FFF;padding:.5rem1rem;border-radius:3px;} .imgzip.itm.cnt{padding:1rem;} .imgzip.itm.cntimg{display:block;max-width:100%;} .imgziptextarea{width:100%;height:20em;} </ style > </ head > < body > < script src = "http://code.jquery.com/jquery-1.8.3.js" ></ script > < input type = "file" accept = "image/*;capture=camera" class = "input" > < div class = "imgzip" ></ div > < script > document.addEventListener('DOMContentLoaded',init,false); functioninit(){ varu=newUploadPic(); u.init({ input:document.querySelector('.input'), callback:function(base64){ $.ajax({ url:"{:U('upload')}", data:{str:base64,type:this.fileType}, type:'post', dataType:'json', success:function(i){ alert(i.info); } }) }, loading:function(){ } }); } functionUploadPic(){ this.sw=0; this.sh=0; this.tw=0; this.th=0; this.scale=0; this.maxWidth=0; this.maxHeight=0; this.maxSize=0; this.fileSize=0; this.fileDate=null; this.fileType=''; this.fileName=''; this.input=null; this.canvas=null; this.mime={}; this.type=''; this.callback=function(){}; this.loading=function(){}; } UploadPic.prototype.init=function(options){ this.maxWidth=options.maxWidth||800; this.maxHeight=options.maxHeight||600; this.maxSize=options.maxSize||3*1024*1024; this.input=options.input; this.mime={'png':'image/png','jpg':'image/jpeg','jpeg':'image/jpeg','bmp':'image/bmp'}; this.callback=options.callback||function(){}; this.loading=options.loading||function(){}; this._addEvent(); }; /** *@description绑定事件 *@param{Object}elm元素 *@param{Function}fn绑定函数 */ UploadPic.prototype._addEvent=function(){ var_this=this; functiontmpSelectFile(ev){ _this._handelSelectFile(ev); } this.input.addEventListener('change',tmpSelectFile,false); }; /** *@description绑定事件 *@param{Object}elm元素 *@param{Function}fn绑定函数 */ UploadPic.prototype._handelSelectFile=function(ev){ varfile=ev.target.files[0]; this.type=file.type //如果没有文件类型,则通过后缀名判断(解决微信及360浏览器无法获取图片类型问题) if(!this.type){ this.type=this.mime[file.name.match(/\.([^\.]+)$/i)[1]]; } if(!/image.(png|jpg|jpeg|bmp)/.test(this.type)){ alert('选择的文件类型不是图片'); return; } if(file.size>this.maxSize){ alert('选择文件大于'+this.maxSize/1024/1024+'M,请重新选择'); return; } this.fileName=file.name; this.fileSize=file.size; this.fileType=this.type; this.fileDate=file.lastModifiedDate; this._readImage(file); }; /** *@description读取图片文件 *@param{Object}image图片文件 */ UploadPic.prototype._readImage=function(file){ var_this=this; functiontmpCreateImage(uri){ _this._createImage(uri); } this.loading(); this._getURI(file,tmpCreateImage); }; /** *@description通过文件获得URI *@param{Object}file文件 *@param{Function}callback回调函数,返回文件对应URI *return{Bool}返回false */ UploadPic.prototype._getURI=function(file,callback){ varreader=newFileReader(); var_this=this; functiontmpLoad(){ //头不带图片格式,需填写格式 varre=/^data:base64,/; varret=this.result+''; if(re.test(ret))ret=ret.replace(re,'data:'+_this.mime[_this.fileType]+';base64,'); callback&&callback(ret); } reader.onload=tmpLoad; reader.readAsDataURL(file); returnfalse; }; /** *@description创建图片 *@param{Object}image图片文件 */ UploadPic.prototype._createImage=function(uri){ varimg=newImage(); var_this=this; functiontmpLoad(){ _this._drawImage(this); } img.onload=tmpLoad; img.src=uri; }; /** *@description创建Canvas将图片画至其中,并获得压缩后的文件 *@param{Object}img图片文件 *@param{Number}width图片最大宽度 *@param{Number}height图片最大高度 *@param{Function}callback回调函数,参数为图片base64编码 *return{Object}返回压缩后的图片 */ UploadPic.prototype._drawImage=function(img,callback){ this.sw=img.width; this.sh=img.height; this.tw=img.width; this.th=img.height; this.scale=(this.tw/this.th).toFixed(2); if(this.sw>this.maxWidth){ this.sw=this.maxWidth; this.sh=Math.round(this.sw/this.scale); } if(this.sh>this.maxHeight){ this.sh=this.maxHeight; this.sw=Math.round(this.sh*this.scale); } this.canvas=document.createElement('canvas'); varctx=this.canvas.getContext('2d'); this.canvas.width=this.sw; this.canvas.height=this.sh; ctx.drawImage(img,0,0,img.width,img.height,0,0,this.sw,this.sh); this.callback(this.canvas.toDataURL(this.type)); ctx.clearRect(0,0,this.tw,this.th); this.canvas.width=0; this.canvas.height=0; this.canvas=null; }; </ script > </ body > </ html > 这个也是把图片转成了base64去传送,个人不建议去用js改变图片的大小,建议裁切缩放还是PHP来做吧。 1 2 3 4 5 this.maxWidth=options.maxWidth||800; this.maxHeight=options.maxHeight||600; this.maxSize=options.maxSize||3*1024*1024; this.input=options.input; this.mime={'png':'image/png','jpg':'image/jpeg','jpeg':'image/jpeg','bmp':'image/bmp'}; 这一部分是对上传图片的配置,应该可以看懂,可以自己去改 1 2 3 4 5 6 7 8 $.ajax({ url:"{:U('upload')}", data:{str:base64,type:this.fileType}, type:'post', dataType:'json', success:function(i){ alert(i.info); } 这部分是上传以后ajax发送base64码到php, base64码带有图片的说明字符串,所以得用正则去掉,然后base64解码保存到图片的文件中。并且返回地址即可 upload.php的内容 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 $str = $_POST [ 'str' ]; $type = $_POST [ 'type' ]; switch ( $type ){ case 'image/png' : $ext = '.png' ; break ; case 'image/jpeg' ; $ext = '.jpeg' ; break ; case 'image/jpeg' : $ext = '.jpg' ; break ; case 'image/bmp' : $ext = '.bmp' ; break ; default : $ext = '.jpg' ; } $file_path = './Uploads/' . date ( 'Ymd' ). '/' .time(). $ext ; if (! file_exists (dirname( $file_path ))){ mkdir (dirname( $file_path ),0777,true); } $img_content = str_replace ( 'data:' . $type . ';base64,' , '' , $str ); $img_content = base64_decode ( $img_content ); $result = file_put_contents ( $file_path , $img_content ); 本文转自 3147972 51CTO博客,原文链接:http://blog.51cto.com/a3147972/1554698,如需转载请自行联系原作者

优秀的个人博客,低调大师

英特尔扩展固态盘产品组合 全面覆盖云到端

在当今的数字世界,无论是在云端、数据中心、PC 还是互联设备上,对于用户而言,能够以一种快速、可靠的方式访问并存储数据十分重要。 从银行和医疗应用,到社交媒体和流媒体娱乐,数据存储解决方案在具备可靠、快速响应和经济高效等优势的同时,还必须能够提供适当的容量。 在此前于美国举办的英特尔云计算日(Cloud Day)大会上,英特尔发布了专为云和企业工作负载优化的全新固态盘产品,旨在支持用户快速且可靠地访问数据。作为英特尔首款使用3D NAND技术的固态盘,英特尔固态盘DC P3320系列相比上一代英特尔固态盘,不仅保持了英特尔固态盘一贯具备的出色服务质量、数据完整性与可靠性的优势,在性价比方面也实现了进一步的提升。 英特尔还同时推出了首款采用NVM Express(NVMe)标准的双端口PCI Express(PCIe)固态盘DC D3700/D3600系列,以全面满足企业关键业务私有云平台与高可用性存储部署的需求。此外,英特尔也扩展了其固态盘产品组合,新增了面向入门级云和数据中心部署、消费级应用、企业PC,以及物联网(IoT)应用的产品。 本文转自d1net(转载)

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册
修改密码
忘记密码