Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @expose()
- @expose("json")
- #@validate(upload_file_form, error_handler=index)
- def uploadfile(self, **kw):
- """
- Upload file into selected folder
- """
- if kw['qqfile'] == None:
- if pylons.request.response_type == 'application/json':
- return dict(error = u'File must be selected first')
- else:
- flash(_(u'ERROR: File must be selected first'))
- redirect(url('/'))
- mediapath = config.get('media.uploadpath', '%(here)s/sung/public/media')
- if pylons.request.response_type == 'application/json'
- uploadfilepath = os.path.join(mediapath, kw['qqfile'])
- else:
- uploadfilepath = os.path.join(mediapath, kw['qqfile'].filename)
- if os.path.exists(uploadfilepath):
- if pylons.request.response_type == 'application/json':
- return dict(error = u'File already exists!')
- else:
- flash(_(u'ERROR: File already exists!'))
- redirect(url('/'))
- writeuploadedfile = file(uploadfilepath, "w")
- if pylons.request.response_type == 'application/json':
- pass
- # Don't know howto get file data
- else:
- writeuploadedfile.write(kw['qqfile'].value)
- writeuploadedfile.close()
- if pylons.request.response_type == 'application/json':
- return dict(success = True)
- else:
- flash("File uploaded successfully")
- redirect(url('/'))
Add Comment
Please, Sign In to add comment