ajaxFileUpload + lua-resty-upload 上传文件
ajaxFileUpload下载地址
地址:http://pan.baidu.com/s/1mgJypz6
html页面
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Untitled</title>
<script src="jquery-1.7.1.js"></script>
<script src="ajaxfileupload.js"></script>
<script type="text/javascript">
$(function () {
$(":button").click(function () {
ajaxFileUpload();
})
})
function ajaxFileUpload() {
$.ajaxFileUpload
(
{
url: '/dsideal_yy/rating/test', //用于文件上传的服务器端请求地址
fileElementId: 'file1', //文件上传空间的id属性 <input type="file" id="file" name="file" />
dataType: 'json', //返回值类型 一般设置为json
success: function (data) //服务器成功响应处理函数
{
alert(data.msg);
}
}
)
return false;
}
</script>
</head>
<body>
<body>
<p><input type="file" id="file1" name="file" /></p>
<input type="button" value="上传" />
</body>
</html>
lua代码
local upload = require "resty.upload"
local uuid = require "resty.uuid"; local chunk_size =
local form = upload:new(chunk_size)
local file --获取文件名
function get_filename(res)
local filename = ngx.re.match(res,'(.+)filename="(.+)"(.*)')
if filename then
return filename[]
end
end --获取文件扩展名
function getExtension(str)
return str:match(".+%.(%w+)$")
end while true do
local typ, res, err = form:read()
if not typ then
ngx.say("{error:'error', msg:'"..tostring(err).."',imgurl:''}")
return
end
if typ == "header" then
if res[] ~= "Content-Type" then
local file_id = uuid.new()
local filen_ame = get_filename(res[])
local extension = getExtension(filen_ame)
local dir = string.sub(file_id,,)
local file_name = "/usr/local/tomcat7/webapps/dsideal_yy/html/down/Material/"..dir.."/"..file_id.."."..extension
if file_name then
file = io.open(file_name, "w+")
if not file then
ngx.say("{error:'error', msg:'failed to open file',imgurl:''}")
return
end
end
end
elseif typ == "body" then
if file then
file:write(res)
end
elseif typ == "part_end" then
file:close()
file = nil
elseif typ == "eof" then
break
else
-- do nothing
end
end ngx.say("{error:'success', msg:'上传成功!',imgurl:''}")
ajaxFileUpload + lua-resty-upload 上传文件的更多相关文章
- Struts Upload上传文件
1.Unable to find 'struts.multipart.saveDir' property setting. Defaulting to javax.servlet.context.te ...
- element-ui upload上传文件并携带参数 使用formData对象
需求:上传文件的时候,需要携带其他的参数 问题:使用upload上传文件时,必须使用formData对象,而其他的参数通过data获取的到的,formData和data是不能同时传输的 解决:获取到的 ...
- thinkphp Upload上传文件在客户端生成的临时文件$_FILES['file']['tmp_name']
1.关于thinkphp 的Upload的$_FILES['file']['tmp_name'] 在使用thinkphp上传图片的时候,在上传的$_FILES数组中,有一个$_FILES['file' ...
- Element-UI中Upload上传文件前端缓存处理
Element-UI对于文件上传组件的功能点着重于文件传递到后台处理,所以要求action为必填属性.但是如果需要读取本地文件并在前端直接处理,文件就没有必要传递到后台,比如在本地打开一个JSON文件 ...
- [javascript] ajaxfileupload.js 跨域上传文件
原文地址: http://www.ueffort.com/jqueryajaxfileupload-js-duo-wen-jian-shang-chuan-chuan-zhi-kua-yu/ 跨域 这 ...
- 异步上传文件,ajax上传文件,jQuery插件之ajaxFileUpload
http://www.cnblogs.com/kissdodog/archive/2012/12/15/2819025.html 一.ajaxFileUpload是一个异步上传文件的jQuery插件. ...
- jquery 实现ajax 上传文件的功能(使用插件 ajaxfileupload)
js文件的下载地址 : http://files.cnblogs.com/wangqc/ajaxfileupload.js 页面代码: <html> <!-- 引入相关的js文 ...
- ajaxfileupload原理及用法,主要用于即想用ajax序列化传递参数,又必须上传文件
一,原理 AjaxFileUpload.js并不是一个很出名的插件,只是别人写好的放出来供大家用,原理都是创建隐藏的表单和iframe然后用JS去提交,获得返回值. 当初做了个异步上传的功能,选择它因 ...
- jquery ajaxFileUpload异步上传文件
ajaxFileUpload.js 很多同名的,因为做出来一个很容易. 我用的是这个:https://github.com/carlcarl/AjaxFileUpload 下载地址在这里:http:/ ...
- jquery.uploadify上传文件配置详解(asp.net mvc)
页面源码: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" c ...
随机推荐
- Page Object Model (Selenium, Python)
时间 2015-06-15 00:11:56 Qxf2 blog 原文 http://qxf2.com/blog/page-object-model-selenium-python/ 主题 Sel ...
- 在python3.5下安装scrapy包
此前scrapy只支持python2.x 但是最新的1.1.0rc1已结开始支持py3了 如果电脑上安装了scrapy的依赖包,诸如lxml.OpenSSL 1.你直接下载Scrapy-1.1.0rc ...
- Delphi中uses在interfeace和implementation中的区别
use单元引入分为在interface中引入,如 interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Co ...
- 知乎大牛的关于JS解答
很多疑惑一扫而空.... http://www.zhihu.com/question/35905242?sort=created JS的单线程,浏览器的多进程,与CPU,OS的对位. 互联网移动的起起 ...
- 数据结构之图 Part3 – 2 遍历
BFS using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ...
- android 入门-控件 测量状态栏高度
private ViewTreeObserver viewTreeObserver; /** 获取可見区域高度 **/ WindowManager manager = getWindowManager ...
- PHPCMS V9 WAP手机门户域名绑定
如需要绑定域名为wap.domain.com,作下如操作: 一.把wap.domain.com域名绑定到你的这个网站主机上. 二.在网站后台模块>手机门户域名里面填写“http://wap.do ...
- sublime text 2 安装emmet插件
一.添加插件之前先 下载Package Control 按 Ctrl+`(就是~这个键) 复制下面的代码 确认 重新启动sublime text2 import urllib2,os;pf='Pack ...
- Visual Studio 2015将在7月20号RTM
(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:用了3个多月的VS 2015终于要迎来RTM了,不过感觉有点淡淡的忧伤(为什么呢?请看 ...
- PMP 第六章 项目时间管理
定义活动 排列活动顺序 估算活动资源 估算活动持续时间 制定进度计划 控制进度计划 1.进度管理计划和进度计划的内容分别是什么,有什么区别? 进度计划:项目各活动计划完成日期的编排. 进度管理计 ...