Guest User

Untitled

a guest
Nov 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. @expose()
  2. @expose("json")
  3. #@validate(upload_file_form, error_handler=index)
  4. def uploadfile(self, **kw):
  5. """
  6. Upload file into selected folder
  7. """
  8.  
  9. if kw['qqfile'] == None:
  10. if pylons.request.response_type == 'application/json':
  11. return dict(error = u'File must be selected first')
  12. else:
  13. flash(_(u'ERROR: File must be selected first'))
  14. redirect(url('/'))
  15.  
  16. mediapath = config.get('media.uploadpath', '%(here)s/sung/public/media')
  17. if pylons.request.response_type == 'application/json'
  18. uploadfilepath = os.path.join(mediapath, kw['qqfile'])
  19. else:
  20. uploadfilepath = os.path.join(mediapath, kw['qqfile'].filename)
  21.  
  22. if os.path.exists(uploadfilepath):
  23. if pylons.request.response_type == 'application/json':
  24. return dict(error = u'File already exists!')
  25. else:
  26. flash(_(u'ERROR: File already exists!'))
  27. redirect(url('/'))
  28.  
  29. writeuploadedfile = file(uploadfilepath, "w")
  30. if pylons.request.response_type == 'application/json':
  31. pass
  32. # Don't know howto get file data
  33. else:
  34. writeuploadedfile.write(kw['qqfile'].value)
  35. writeuploadedfile.close()
  36.  
  37. if pylons.request.response_type == 'application/json':
  38. return dict(success = True)
  39. else:
  40. flash("File uploaded successfully")
  41. redirect(url('/'))
Add Comment
Please, Sign In to add comment