Advertisement
Guest User

Uploading file from forms

a guest
Jun 22nd, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. def save_file(file, path=''):
  2.             filename = file._get_name()
  3.             filename_wo_extension_index = filename.find(".")
  4.             filename_wo_extension=filename[0:filename_wo_extension_index]
  5.             #instance.icon = filename_wo_extension
  6.             destination_new = os.path.join(ROOT_DIR, 'arches/Media/images/AssetIcons/')
  7.             os.chdir(destination_new)
  8.             if os.path.exists(destination_new) == "True":
  9.                 with open('%s' % filename, "wb+") as destination:
  10.                     for chunk in file.chunks():
  11.                         destination.write(chunk)
  12.             else:
  13.                 with open('%s' % filename, "wb+") as destination :
  14.                     for chunk in file.chunks():
  15.                         destination.write(chunk)
  16.            
  17.             #add support for uploading icon file
  18.         if 'file' in request.FILES:
  19.             save_file(request.FILES['file'])
  20.         else:
  21.             #instance.icon = request.POST.get('icon')
  22.             pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement