改写BlogEngine.NET头像上传实现方式(使用baidu.flash.avatarMaker)
baidu.flash.avatarMaker
需要资源文件和javascript类库:
|
1
2
3
4
5
6
7
|
需要应用的script library:<scriptsrc="@Url.Content("~/Areas/Admin/Scripts/baidu/tangram-custom-full-yui.js")"></script><scriptsrc="@Url.Content("~/Areas/Admin/Scripts/baidu/flash.js")"></script><scriptsrc="@Url.Content("~/Areas/Admin/Scripts/baidu/flash/_Base.js")"></script><scriptsrc="@Url.Content("~/Areas/Admin/Scripts/baidu/flash/avatarMaker.js")"></script>需要的使用的资源文件:@Url.Content("~/Areas/Admin/Scripts/baidu/flash/avatarMaker.swf") |
HTML:
|
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
|
<scriptlanguage='javascript'type='text/javascript'> var info = baidu.g("fileInfoScope"); /** * 创建flash based avatarMaker * param {Object} createOptions 创建flash时需要的参数,请参照baidu.swf.create文档 * config {Object} vars 创建avatarMaker时所需要的参数 * config {String} [vars.locale] 地区,现在支持vi、th、ar三种,分别是越南语、泰语和阿拉伯语,当使用阿拉伯语时,界面会变成rtl形式,默认为[zh-cn] * config {String} [vars.bigFileName] 80*80图片文件数据字段名,默认为'bigFile' * config {String} [vars.middleFileName] 60*60图片文件数据字段名,默认为'middleFile' * config {String} [vars.smallFileName] 60*60图片文件数据字段名,默认为'smallFile' * config {Number} [vars.imageQuality] 图片的压缩质量0-100, 默认为 80 * config {String} uploadURL 上传图片到的url地址 * config {Function|String} tipHandler js提示函数,当flash发生异常,调用此函数显示出错信息。该函数接收一个String类型的参数,为需要显示的文字 * config {Function|String} uploadCallBack 上传之后的回调函数 */ var options = { vars: { locale: 'zh-cn', bigFileName: 'bigFileName', middleFileName: 'middleFileName', smallFileName: 'smallFileName', imageQuality: 100 }, uploadURL: "@Url.Action("UploadAvatar", "Users", new { Area = "Admin", id = ViewBag.theId })", tipHandle: function (tip) { alert(tip); }, uploadCallBack: function (data) { data = JSON.parse(data); // 处理完毕后的操作。例如 window.location ='xxxxx/xxxxx'; // alert("头像更换成功。"); if (data.Success) { ShowStatus("success", data.Message); } else { ShowStatus("warning", data.Message); } }, createOptions: { id: "flashID", url: "@Url.Content("~/Areas/Admin/Scripts/baidu/flash/avatarMaker.swf")", width: "630px", height: "360px", container: "fileContentScope" } }; var t = function () { var d = new Date(); return [d.getHours(), d.getMinutes(), d.getSeconds()].join(":") }; var up; function clll() { up.upload(); } var LoadProfile = function () { var dto = { "id": "@ViewBag.theId" }; $.ajax({ url: "@Url.Action("GetProfile", "Users", new { Area = "Admin" })", data: ko.toJSON(dto), type: "POST", contentType: "application/json; charset=utf-8", dataType: "json", beforeSend: onAjaxBeforeSend, success: function (msg) { $('#Container').setTemplateURL(SiteVars.TemplatesFilePath + '/profile.htm', null, { filter_data: false }); $('#Container').processTemplate(msg.Data); $("#hiddenUploadButton").hide(); up = new baidu.flash.avatarMaker(options); $("#hiddenUploadButton").show(); $('#Container2').setTemplateURL(SiteVars.TemplatesFilePath + '/profile2.htm', null, { filter_data: false }); $('#Container2').processTemplate(msg.Data); $(".rowTools").accessibleDropDown(); } }); }; LoadProfile();</script><divid="fileContentScope"style="width: 630px; height: 360px; padding: 10px; display: block; border: 1px solid #ddd;"></div><divid="fileInfoScope"style="width: 630px; height: auto; line-height: 20px; border: 1px solid #ddd; border-top: 0px; font-size: 12px; padding: 10px;"> <pstyle="color: #666"> 图片说明:<br/> 每次上传的文件覆盖前面的文件。上传后的路径为: ~/upload/<br/> 以字母b结尾的为大图(130x130 像素),以字母m结尾的为中图(55x55像素),以s结尾的为小图(35x35像素)</p> <inputid="hiddenUploadButton"type="button"value="上传"onclick="clll()"/> </div> |
|
|
c#代码:
|
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
|
public JsonResult UploadAvatar(string id) { JsonResponse jsonData = new JsonResponse(); jsonData.Success = false; string login = string.IsNullOrEmpty(id) ? Security.CurrentUser.Identity.Name : id; string theFileName = "middleFileName"; try { for (int i = 0; i < Request.Files.Count; i++) { // the upload file name string fileName = Request.Files.Get(i).FileName; if (string.Compare(fileName, theFileName, true) != 0) { continue; } fileName = string.Concat(fileName, ".png"); //~/App_Data/files/avatars/Primary/admin/ string fileSaveDirectory = string.Concat(BlogConfig.StorageLocation, "files/avatars", "/", Blog.CurrentInstance.Name, "/", login); //~/App_Data/files/avatars/Primary/admin/middleFileName string fileSavePath = string.Concat(fileSaveDirectory,"/", fileName); // ensure the diectory exists if (!BlogService.DirectoryExists(@fileSaveDirectory)) { BlogService.CreateDirectory(@fileSaveDirectory); } // case the file path has exist just delete it. if (BlogService.FileExists(@fileSavePath)) { BlogService.DeleteFile(@fileSavePath); } // upload file BlogService.UploadFile(Request.Files.Get(i).InputStream, fileName, BlogService.GetDirectory(fileSaveDirectory), true); } var pf = AuthorProfile.GetProfile(login) ?? new AuthorProfile(login); // /Images/avatars/Primary/admin//middleFileName.png pf.PhotoUrl = string.Join("/", new string[] { Blog.CurrentInstance.Name, login, string.Concat(theFileName, ".png") }); pf.Save(); jsonData.Success = true; jsonData.Message = "上传文件成功!"; } catch (Exception ex) { LogUtil.Log(string.Concat(DateTime.Now.ToString(), ex.Message)); jsonData.Success = false; jsonData.Message = "上传文件失败!"; } return Json(jsonData); } |
本文看点:
看了BlogEngine.NET中的实现代码显然是没有使用BlogEngine.Core中提供的文件资源类库,本示例:提供了使用BlogEngine.Core文件资源库使用方法。
使用了baidu.flash.avatarMaker类库实现了在ASP.NET mvc中,实现图片截取,上传功能。
领悟:
baidu的脚本现在做的很强大呀,特别是他的百度地图功能中的脚本相当有水平呀。
读开源程序,别人的思想真的让人感慨很多,比如:BlogEngine.Core中的文件资源库,功能实现的接口方法提供XML,UC,DB几种实现,可谓之功能强大了,接口类的命名实在是佩服,感觉像是在用Directory和File类一样。
希望给读者们提供更多帮助。
参考资源:
http://www.cnblogs.com/snake-hand/archive/2013/06/14/3136997.html[但感觉本文中,提到的一些资源也很致命呀,c#代码接收文件地方的文件名错误;需要的资源库讲的不全]
https://github.com/BaiduFE/Tangram-component Tangram-component
http://tangram.baidu.com/ Tangram官网
改写BlogEngine.NET头像上传实现方式(使用baidu.flash.avatarMaker)的更多相关文章
- 强大的flash头像上传插件(支持旋转、拖拽、剪裁、生成缩略图等)
今天介绍的这款flash上传头像功能非常强大,支持php,asp,jsp,asp.net 调用 头像剪裁,预览组件插件. 本组件需要安装Flash Player后才可使用,请从http://dl.pc ...
- 【Bootstrap-插件使用】Jcrop+fileinput组合实现头像上传功能
作者:Dreawer链接:https://zhuanlan.zhihu.com/p/24465742来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 作者:梦游的龙猫(转 ...
- [Bootstrap-插件使用]Jcrop+fileinput组合实现头像上传功能
很久没有更新博客了,再不写点东西都烂了. 这次更新一个小内容,是两个插件的组合使用,实现头像上传功能. 业务需求: 头像上传功能,要对上传的文件进行剪切,且保证头像到服务器时必须是正方形的. 优化&l ...
- Canvas处理头像上传
未分类 最近社区系统需要支持移动端,其中涉及到用户头像上传,头像有大中小三种尺寸,在PC端,社区用Flash来处理头像编辑和生成,但该Flash控件的界面不友好而且移动端对Flash的支持不好,考虑到 ...
- php+flash头像上传组件
有会员系统的站点一般都会有一个头像上传组件,一般做的最简单的是 这样的方式长处是代码写的简单,仅仅要推断图片大小和类型,然后更新数据库.可是用户体验不高.并且站点其它页面假设要使用较小的20X20或1 ...
- php头像上传预览
php头像上传带预览: 说道上传图片,大家并不陌生,不过,在以后开发的项目中,可能并不会让你使用提交刷新页面式的上传图片,比如上传头像,按照常理,肯定是在相册选择照片之后,确认上传,而肯定不会通过fo ...
- qt实现头像上传功能
想必大家都使用过qt的自定义头像功能吧,那么图1应该不会陌生,本片文章我就是要模拟一个这样的功能,虽然没有这么强大的效果,但是能够满足一定的需求. 图1 qq上传图片 首先在讲解功能之前,我先给出一片 ...
- Django实现注册页面_头像上传
Django实现注册页面_头像上传 Django实现注册页面_头像上传 1.urls.py 配置路由 from django.conf.urls import url from django.cont ...
- android头像上传(获取头像加剪切)
因为项目中需要用到头像上传的功能,所以就下个Ddmo先来实现下. demo我是类似仿微信的,在一个GridView中展示所有的图片,其中第一个item可以去照相:获取到图片后再进行剪切. 图片的剪切是 ...
随机推荐
- 肢体语言心理学+FBI阅人术(行为心理学) 用最短的时间了解一个人
肢体语言心理学 如何从站姿判断人 每个人都有自己习惯的站立姿势.美国夏威夷大学心理学家指出,不同的站姿可以显示出一个人的性格特征. 站立时习惯把双手插入裤袋的人:城府较深,不轻易向人表露内心 ...
- 错误提示 Unsupported compiler 'com.apple.compilers.llvmgcc42' selected for architecture 'i386'
转自http://blog.csdn.net/cyuyanenen/article/details/51444974 警告提示:Invalid C/C++ compiler in target Cor ...
- SPOJ 705 New Distinct Substrings
后缀数组.按照排序完的后缀一个一个统计.每一个后缀对答案做出的贡献为:n-SA[i]-height[i]. #pragma comment(linker, "/STACK:102400000 ...
- 用Replace Pioneer 提取正则内容
推荐用软件Replace Pioneer完成,支持正则表达式和文本替换,提取,很灵活容易. 以下举例说明怎样把<a href 和 </a>之间的内容提取出来,其他的全部删除. 1. ...
- 在选定的数据源上未找到名为“TitleSub”的字段或属
在.NET开发过程中时常会遇到“在选定的数据源上未找到名为“TitleSub”的字段或属性”的错误”,导致这类错误的原因有很多,在我的项目中,详细情况是这样:1.有两个控件:DropDownList类 ...
- UVa 1395 (最小生成树)
题目链接:http://vjudge.net/problem/41567/origin 本来想着m^2的复杂度撑不住,对于这种擦着边的复杂度就好慌. 首先对所有的边排个序,然后枚举每个可以构成生成树的 ...
- 初识mongo
进入mongo /usr/local/mongodb/bin/mongo --host 查看所有db show dbs 查看当前进入的db db 查看当前db的所有collection show co ...
- 关于C++中虚函数表存放位置的思考
其实这是我前一段时间思考过的一个问题,是在看<深入探索C++对象模型>这本书的时候我产生的一个疑问,最近在网上又看到类似的帖子,贴出来看看: 我看到了很多有意思的答案,都回答的比较好,下面 ...
- WdatePicker默认日期为当天
不说废话,直接上代码: <input id="d4311" class="Wdate" onfocus="WdatePicker({maxDat ...
- rownum使用方法
rownum使用方法: .使用rownum子查询: rownum是一个总是从1开始的伪列,当查询条件rownum)时,不能从数据库查到记录,因此要 通过子查询解决:; 结果: SQL; R ID US ...