def upload_file(request):
if request.method != 'POST':
return error(request, 'Wrong HTTP method!')
try:
filename = request.GET['filename']
except KeyError:
return error(request, 'Need a filename param!')
if not os.path.exists(settings.CML_UPLOAD_ROOT):
try:
os.makedirs(settings.CML_UPLOAD_ROOT)
except OSError:
return error(request, 'Can\'t create upload directory!')
filename = os.path.basename(filename)
temp_file = SimpleUploadedFile(filename, request.read(), content_type='text/xml')
with open(os.path.join(settings.CML_UPLOAD_ROOT, filename), 'wb') as f:
for chunk in temp_file.chunks():
f.write(chunk)
return success(request)
评论列表
文章目录