django ajax上传文件
来源:互联网 发布:vm安装mac os 编辑:程序博客网 时间:2024/05/22 12:44
文件上传
https://www.bbsmax.com/A/l1dyQexdem/
<script type="text/javascript">
function uploadImage() {
$.ajaxFileUpload({
url: "/Struts2Upload/test/uploadAjax.action",
secureuri:false,
fileElementId:"btn_file",
data:{lbg:"json传值并且返回"},
dataType: "json",
error: function(data, status, e) {
alert("shibai");
alert(e);
},
success: function(data, textStatus) {
alert(textStatus);
$('img').attr('src',data.imPath);
}
});
}
</script>
<input type="file" id="btn_file" name="btn_file" onchange="uploadImage();">
处理图片:
def pic_class(request): upload_file = request.FILES.get("myfile", None) # 获取上传的文件,如果没有文件,则默认为None file_obj = request.FILES.get('file') if file_obj: # 处理附件上传到方法 request_set = {} print('file--obj', file_obj) # user_home_dir = "upload/%s" % (request.user.userprofile.id) # accessory_dir = settings.accessory_dir # if not os.path.isdir(accessory_dir): # os.mkdir(accessory_dir) scr = Image.open(file_obj) img= np.asarray(scr)
with open(upload_file, 'wb') as new_file: for chunk in file_obj.chunks(): new_file.write(chunk)
### get the inmemory file
data = request.FILES.get('btn_file') # get the file from the curl
### write the data to a temp file
tup = tempfile.mkstemp() # make a tmp file
f = os.fdopen(tup[0], 'w') # open the tmp file for writing
f.write(data.read()) # write the tmp file
f.close()
### return the path of the file
filepath = tup[1] # get the filepath
return filepath
阅读全文
0 0
- django ajax上传文件
- ajax+django异步上传文件
- Django的AJAX实现之文件上传
- Django的Ajax实现之文件上传
- Ajax 和 jQuery 实现进度条+上传文件到Django
- Django - 上传文件(初稿)
- django 文件上传
- django 文件上传
- Django的文件上传
- django上传文件
- django 文件上传
- django上传文件
- django 上传文件
- django上传文件
- Django文件上传
- django实现文件上传
- Django form 文件上传
- Django实现文件上传
- codevs 1082 线段树练习 3(区间修改+区间求和)
- 【DDD】领域驱动设计实践 —— 业务建模小招数
- 在MFC中选择要打开文件的路径
- POJ 2079 Triangle(凸包+旋转卡壳,求最大三角形面积)
- java中的堆和栈空间
- django ajax上传文件
- 头文件#include<bits/stdc++.h>
- babel+browserify用法总结
- Java 坑
- node+mongodb建站攻略(1)
- 通信
- c# 从一个大图里截取图形
- django ajax传参数
- centos7安装mysql5.7.19及配置远程连接