1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-16 07:08:55 +00:00

Merge branch 'upload'

This commit is contained in:
xiez
2012-07-05 16:14:39 +08:00
4 changed files with 17 additions and 5 deletions

View File

@@ -186,7 +186,7 @@ CACHES = {
} }
} }
MAX_UPLOAD_FILE_SIZE = 1024 * 1024 * 1024 # 1GB MAX_UPLOAD_FILE_SIZE = 100 * 1024 * 1024 # 100 MB
MAX_UPLOAD_FILE_NAME_LEN = 256 MAX_UPLOAD_FILE_NAME_LEN = 256
# Base url and name used in email sending # Base url and name used in email sending

View File

@@ -18,6 +18,7 @@
{% for name, link in zipped %} {% for name, link in zipped %}
<a href="{{ SITE_ROOT }}repo/{{ repo.id }}/?p={{ link|urlencode }}">{{ name }}</a> / <a href="{{ SITE_ROOT }}repo/{{ repo.id }}/?p={{ link|urlencode }}">{{ name }}</a> /
{% endfor %} {% endfor %}
(最大不得超过 {{ max_upload_file_size|filesizeformat }})
</h3> </h3>
<form id="upload-file-form" enctype="multipart/form-data" method="post"> <form id="upload-file-form" enctype="multipart/form-data" method="post">
<input type="hidden" name="parent_dir" id="parent_dir" value="{{ parent_dir }}" /> <input type="hidden" name="parent_dir" id="parent_dir" value="{{ parent_dir }}" />

View File

@@ -109,7 +109,6 @@ class UploadProgressCachedHandler(FileUploadHandler):
super(UploadProgressCachedHandler, self).__init__(request) super(UploadProgressCachedHandler, self).__init__(request)
self.progress_id = None self.progress_id = None
self.cache_key = None self.cache_key = None
self.chunk_size = 1024
def handle_raw_input(self, input_data, META, content_length, boundary, encoding=None): def handle_raw_input(self, input_data, META, content_length, boundary, encoding=None):
self.content_length = content_length self.content_length = content_length

View File

@@ -273,6 +273,7 @@ def repo_upload_file(request, repo_id):
"used_space": used_space, "used_space": used_space,
"total_space": total_space, "total_space": total_space,
"zipped": zipped, "zipped": zipped,
"max_upload_file_size": settings.MAX_UPLOAD_FILE_SIZE,
}, context_instance=RequestContext(request)) }, context_instance=RequestContext(request))
############ POST ############ ############ POST ############
@@ -286,6 +287,7 @@ def repo_upload_file(request, repo_id):
"total_space": total_space, "total_space": total_space,
"zipped": zipped, "zipped": zipped,
"parent_dir": parent_dir, "parent_dir": parent_dir,
"max_upload_file_size": settings.MAX_UPLOAD_FILE_SIZE,
}, context_instance=RequestContext(request)) }, context_instance=RequestContext(request))
try: try:
@@ -299,23 +301,33 @@ def repo_upload_file(request, repo_id):
error_msg = u'上传文件失败' error_msg = u'上传文件失败'
return render_upload_error(error_msg) return render_upload_error(error_msg)
def remove_tmp_file():
try:
os.remove(tmp_file.temporary_file_path())
except:
pass
# rename the file if there is name conflicts # rename the file if there is name conflicts
filename = check_filename_with_rename(repo_id, parent_dir, tmp_file.name) filename = check_filename_with_rename(repo_id, parent_dir, tmp_file.name)
if len(filename) > settings.MAX_UPLOAD_FILE_NAME_LEN: if len(filename) > settings.MAX_UPLOAD_FILE_NAME_LEN:
remove_tmp_file()
error_msg = u"您上传的文件名称太长" error_msg = u"您上传的文件名称太长"
return go_error(request, error_msg) return go_error(request, error_msg)
if tmp_file.size > settings.MAX_UPLOAD_FILE_SIZE: if tmp_file.size > settings.MAX_UPLOAD_FILE_SIZE:
error_msg = u"您上传的文件太大" error_msg = u"您上传的文件太大"
remove_tmp_file()
return go_error(request, error_msg) return go_error(request, error_msg)
try: try:
seafserv_threaded_rpc.put_file (repo_id, tmp_file_path, parent_dir, seafserv_threaded_rpc.put_file (repo_id, tmp_file_path, parent_dir,
filename, request.user.username); filename, request.user.username);
except SearpcError, e: except SearpcError, e:
remove_tmp_file()
error_msg = e.msg error_msg = e.msg
return render_upload_error(error_msg) return render_upload_error(error_msg)
else:
remove_tmp_file()
url = reverse('repo', args=[repo_id]) + ('?p=%s' % parent_dir) url = reverse('repo', args=[repo_id]) + ('?p=%s' % parent_dir)
return HttpResponseRedirect(url) return HttpResponseRedirect(url)