Created
May 30, 2014 07:09
-
-
Save mmahesh/dab0e341add142864649 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
#Templates | |
<input type="file" class="btn btn-default" id="dish_file" name="dish_file"> | |
#Views | |
def some_view(request): | |
# some check over here | |
# the following code is to copy the uploaded file but these doesnt seem to be working | |
upload_directory = settings.MEDIA_INDEX | |
print(upload_directory) | |
my_filename = request.FILES['dish_file'].name | |
my_file = request.FILES['dish_file'] | |
f = my_file.read() | |
print(len(f)) | |
if len(f)> 500: | |
print("this is too big") | |
print(my_file) | |
saved_file = (str(upload_directory) +'/'+ "%s_%s")%(str(time()).replace('.','_'),my_filename) | |
print(saved_file) | |
perm_file = open(saved_file, 'wb') | |
shutil.copyfileobj(my_file, perm_file) | |
my_file.close() | |
perm_file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment