daily pastebin goal
75%
SHARE
TWEET

Uploading file from forms

a guest Jun 22nd, 2014 188 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top