blob

js 上传文件模拟Form 表单

£可爱£侵袭症+ 提交于 2020-02-02 14:35:21
使用FormData对象 在本文章中 创建一个FormData对象 使用HTML表单来初始化一个FormData对象 使用FormData对象发送文件 利用 FormData 对象,你可以使用一系列的键值对来模拟一个完整的表单,然后使用 XMLHttpRequest 发送这个"表单". 创建一个FormData对象 你可以先创建一个空的 FormData 对象,然后使用 append() 方法向该对象里添加字段,如下: var oMyForm = new FormData(); oMyForm.append("username", "Groucho"); oMyForm.append("accountnum", 123456); // 数字123456被立即转换成字符串"123456" // fileInputElement中已经包含了用户所选择的文件 oMyForm.append("userfile", fileInputElement.files[0]); var oFileBody = '<a id="a"><b id="b">hey!</b></a>'; // Blob对象包含的文件内容 var oBlob = new Blob([oFileBody], { type: "text/xml"}); oMyForm.append("webmasterfile", oBlob)

Convert blob to image file

倾然丶 夕夏残阳落幕 提交于 2020-02-02 13:32:15
问题 I am trying to convert an image file captured from an input type=file element without success. Below is my javascript code var img = document.getElementById('myimage'); var file = document.querySelector('input[type=file]').files[0]; var reader = new FileReader(); reader.addEventListener("load", function () { var theBlob = reader.result; theBlob.lastModifiedDate = new Date(); theBlob.name = file; img.src = theBlob; var newfile = new File([theBlob], "c:files/myfile.jpg"); }, false); if (file) {

Blob,DataURL和File之间的转换

*爱你&永不变心* 提交于 2020-01-30 03:49:41
Blob对象是一个不可变、原始数据的类文件对象 File对象继承于Blob,并具有支持用户系统上的文件的拓展功能 DataURL是Base64编码,可通过window下的btoa,atob方法来分别做编码和解码 DataURL转成File对象 /** * @param {String} dataurl 传入的文件base64编码 * @param {String} filename 文件名 * @param {String} type 文件类型 */ export const dataURLtoFile = (dataurl, filename = "file", type) => { let arr = dataurl.split(","); let bstr = atob(arr[1]); !type && (type = arr[0].replace("data:", "").replace(";base64", "")); let n = bstr.length, u8arr = new Uint8Array(n); while (n--) { u8arr[n] = bstr.charCodeAt(n); } return new File([u8arr], filename, { type }); }; DataURL转化为Blob对象 /** * @param

MySQL基础篇(2)数据类型

早过忘川 提交于 2020-01-28 06:27:02
  MySQL提供了多种数据类型,主要包括数值型、字符串类型、日期和时间类型。   1.数值类型 整数类型:TINYINT(1字节)、SMALLINT(2字节)、MEDIUMINT(3字节)、INT(INTEGER)(4字节)、BIGINT(8字节) 浮点类型:FLOAT(4字节)、DOUBLE(8字节) 定点数类型:DEC(M,D)(M + 2字节)、DECIMAL(M,D)(M+2字节) 位类型:BIT(M)(1~8字节)   (1)整数类型   MySQL支持在类型名称后面的小括号内指定显示宽度,例如int(5)表示当数值宽度小于5位的时候在数字前面填满宽度,如果指示显示宽度则默认为int(11)。一般配合zerofill使用,zerofill就是用‘0’填充的意思,也就是在数字位数不够的空间用字符‘0’填满。 mysql> create table t1(id1 int, id2 int(5)); Query OK, 0 rows affected (0.01 sec) mysql> desc t1; +-------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+-------

GitHub 优秀的 Android 开源项目

♀尐吖头ヾ 提交于 2020-01-27 04:06:54
转自:http://blog.csdn.net/shulianghan/article/details/18046021 主要介绍那些不错个性化的View,包括ListView、ActionBar、Menu、ViewPager、Gallery、GridView、ImageView、ProgressBar及其他如Dialog、Toast、EditText、TableView、Activity Animation等等。    一、ListView android-pulltorefresh 一个强大的拉动刷新开源项目,支持各种控件下拉刷新 ListView、ViewPager、WevView、ExpandableListView、GridView、(Horizontal )ScrollView、Fragment上下左右拉动刷新,比下面johannilsson那个只支持ListView的强大的多。并且他实现的下拉刷新ListView在item不足一屏情况下也不会显示刷新提示,体验更好。 项目地址: https://github.com/chrisbanes/Android-PullToRefresh Demo地址: https://github.com/Trinea/TrineaDownload/blob/master/pull-to-refreshview-demo.apk?raw

前端利用canvas给图片添加水印

亡梦爱人 提交于 2020-01-26 05:22:33
本文发布于我的个人网站: http://wintc.top/article/27 ,转载请注明。   前两天给个人网站添加了一个小功能,就是在文章编辑上传图片的时候自动给图片加上水印。给网页图片添加水印是个常见的功能,也是互联网内容作者保护自己版权的方法之一。本文简单记录一下借助 canvas 在前端实现图片添加水印的实现方法。   canvas元素其实就是一个画布,我们可以很方便地绘制一些文字、线条、图形等,它也可以将一个img标签里渲染的图片画在画布上。   我们在上传文件到后端的时候,使用input标签读取用户本地文件后得到的其实是一个 Blob 对象(更精确的说是File对象,特殊的Blob对象);而在页面上展示一个图片使用的是img标签;绘制功能用canvas实现。添加水印的功能需要在img标签、canvas画布、Blob对象这三者之间相互转换,通过一些API可以完成这个工作:   我们可以从本地读取图片Blob,然后渲染到img标签,使用canvas绘制img内容并且绘制水印内容到画布,再将canvas内容转为Blob对象上传服务器,这样就完整实现了图片+水印的功能。 一、本地读取图像文件渲染到img标签   本地读取图片文件将会得到一个Blob对象,我们可以借助 FileReader.readAsDataURL 方法读取Blob的内容

前端通用下载文件方法(兼容IE)

对着背影说爱祢 提交于 2020-01-26 03:31:49
之前在网上看到一个博主写的前端通用的下载文件的方法,个人觉得很实用,所以mark一下,方便以后查阅 源文地址 (源文还有上传/下载excel文件方法) 因为项目要求要兼容IE浏览器,所以完善了一下之前博主的方法 IE 浏览器:使用微软自带的msSaveBlob 方法,a标签的download属性不支持IE 谷歌浏览器(只测试过谷歌):创建a标签 ,添加download属性,模拟鼠标点击事件    //这里res.data是返回的blob对象 var blob = new Blob([res.data.fileData], {type: 'application/json;charset=utf-8'}); //application/vnd.openxmlformats-officedocument.wordprocessingml.document这里表示doc类型 var href = window.URL.createObjectURL(blob); //创建下载的链接 if (window.navigator.msSaveBlob) { try { window.navigator.msSaveBlob(blob, 'model.json') } catch (e) { console.log(e); } } else { // 谷歌浏览器 创建a标签

caffe深度模式的组成模块:Blobs,Layers,and Nets

杀马特。学长 韩版系。学妹 提交于 2020-01-25 13:21:44
1.blob (caffe中的数据操作基本单位) Blobs封装了运行时的数据信息,提供了CPU和GPU的同步。 图片数据: Blob可以表示为(N C H*W)这样一个4D数组 其中:N表示图片的数量;C表示图片的通道数;H和W分别表示图片的高度和宽度。 在模型中设定的参数,也是用Blob来表示和运算。它的维度会根据参数的类型不同而不同。 Blob是用以存储数据的4维数组,例如 对于数据:Number Channel Height Width 对于卷积权重:Output Input Height Width 对于卷积偏置:Output 1 1*1 举个栗子: 在一个卷积层中,输入一张3通道图片,有96个卷积核,每个核大小为11 11,因此这个Blob是96 3 11 11; 在一个全连接层中,假设输入1024通道图片,输出1000个数据,则Blob为1000*1024。 2、layer (层是网络模型的组成要素和计算的基本单位) 层的类型比较多,如Data,Convolution,Pooling,ReLU,Softmax-loss,Accuracy等;其中一个层的定义大致如下: 从bottom进行数据的输入 ,计算后,通过top进行输出。图中的黄色多边形表示输入输出的数据,蓝色矩形表示层。 每一种类型的层都定义了三种关键的计算:setup,forward and backword

How to save one Doctrine entity to two database tables (required for MySQL optimisation)

流过昼夜 提交于 2020-01-25 11:43:09
问题 In my database I've a table file and a table file_content . The file table stores the metadata of the file such as name , mime and some more. The file_content stores a blob with the file content. I'm not storing the blob in the same table as the metadata for performance reasons only. For a 'version 2' of my project I'm looking into Doctrine (2.3). To me, a "File" seems to be one entity, with properties such as name , mime , extension , content that should be used like this: $file = new File()

How to save one Doctrine entity to two database tables (required for MySQL optimisation)

心不动则不痛 提交于 2020-01-25 11:42:30
问题 In my database I've a table file and a table file_content . The file table stores the metadata of the file such as name , mime and some more. The file_content stores a blob with the file content. I'm not storing the blob in the same table as the metadata for performance reasons only. For a 'version 2' of my project I'm looking into Doctrine (2.3). To me, a "File" seems to be one entity, with properties such as name , mime , extension , content that should be used like this: $file = new File()