Django或ASP.NET中的基于网页的大文件上传及续传功能
我们正在寻找一种方法来开发一个基于网页的应用程序,这个应用程序需要能够上传大文件(大小可以达到10GB),并且要有断点续传的功能。
我们希望使用python/django或者C#/asp.net来开发这个应用。
任何建议都非常欢迎。
2 个回答
1
使用plupload和Java后端,可以支持上传任意大小的文件。
你可以查看这个链接:https://github.com/jakobadam/plupload-java-runtime
你需要把上传的部分移植到Django框架中。大概可以这样做。不过,这段代码并没有进行任何校验和验证。
def fileUpload(request):
"""file upload for plupload"""
if request.method == 'POST':
name = request.REQUEST.get('name','')
uploaded_file = request.FILES['file']
if not name:
name = uploaded_file.name
name,ext = os.path.splitext(name)
#check to see if a user has uploaded a file before, and if they have
#not, make them a upload directory
upload_dir = "/results/referenceLibrary/temp/"
if not os.path.exists(upload_dir):
return render_to_json({"error":"upload path does not exist"})
dest_path = '%s%s%s%s' % (upload_dir,os.sep,name,ext)
chunk = request.REQUEST.get('chunk','0')
chunks = request.REQUEST.get('chunks','0')
md5chunk = request.REQUEST.get('md5chunk', False)
md5total = request.REQUEST.get('md5total', False)
debug = [chunk, chunks, md5chunk, md5total]
with open(dest_path,('wb' if chunk==0 else 'ab')) as f:
for content in uploaded_file.chunks():
f.write(content)
if int(chunk) + 1 >= int(chunks):
#the upload has finished
pass
return render_to_json({"chuck posted":debug})
else:
return render_to_json({"method":"only post here"})
0
用浏览器的标准上传功能来处理这么大的文件简直是疯狂的。对于这种文件,你最好使用FTP功能,把文件放到一个磁盘上。在.NET中,你可以设置一个Windows服务来监控某个文件夹,如果有文件放进去,就可以做出相应的处理。为了帮助你实现这个功能,.NET提供了一个叫做FileSystemWatcher类的工具。