Created
January 28, 2015 09:02
-
-
Save zubairalam/1dd527bbfb7bd19949eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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