Skip to content

Instantly share code, notes, and snippets.

@zubairalam
Created January 28, 2015 09:02
Show Gist options
  • Save zubairalam/1dd527bbfb7bd19949eb to your computer and use it in GitHub Desktop.
Save zubairalam/1dd527bbfb7bd19949eb to your computer and use it in GitHub Desktop.
@csrf_exempt
def upload_video_file(request):
folder = 'tmp_dir2/' #request.path.replace("/", "_")
uploaded_filename = request.FILES['file'].name
BASE_PATH = '/home/'
# create the folder if it doesn't exist.
try:
os.mkdir(os.path.join(BASE_PATH, folder))
except:
pass
# save the uploaded file inside that folder.
full_filename = os.path.join(BASE_PATH, folder, uploaded_filename)
fout = open(full_filename, 'wb+')
file_content = ContentFile( request.FILES['file'].read() )
try:
# Iterate through the chunks.
for chunk in file_content.chunks():
fout.write(chunk)
fout.close()
html = "<html><body>SAVED</body></html>"
return HttpResponse(html)
except:
html = "<html><body>NOT SAVED</body></html>"
return HttpResponse(html)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment