def post(self): preview = Preview(self.request) type_pv = self.request.GET.get('type') if type_pv not in [u'team', u'user']: raise HTTPBadRequest('Expect type = team or user') width, height = self.DIMENTIONS[type_pv] res = dict(status='error', msg='', file={}) file = self.request.POST['file'] data = preview.upload_data(file.file.read()) size = len(data) mimetype = mimetypes.guess_type(file.filename)[0] filename = str(self.request.user.id) if size and mimetype[:5] == 'image': data = h.image_resize(data, 's', width, height) preview.file_write(os.path.join(self.settings['AVATAR_PATH'], 'previews', filename), data) res['status'] = 'ok' res['file'] = { 'url': '/api/images/previews/%s' % filename, 'filename': filename, 'mime': mimetype, 'size': size } return res
def dispatch(self): user_id = self.request.GET.get('user_id') if user_id and self.request.has_perm('admin'): user = User.query.get(user_id) else: user = self.request.user res = dict(status='error', msg='', file={}) if self.request.method == 'POST': file = self.request.POST['file'] data = self._upload_data(file.file.read()) size = len(data) mimetype = mimetypes.guess_type(file.filename)[0] if size and mimetype[:5] == 'image': data = h.image_resize(data, 's', 100, 100) self._file_write( _avatar_path(user.id, self.request.registry.settings, True), data) res['status'] = 'ok' res['file'] = { 'url': self.request.url_for('/user/avatar_temp', user_id=user.id), 'filename': file.filename, 'mime': mimetype, 'size': size } return res
def dispatch(self): user_id = self.request.GET.get('user_id') if user_id and self.request.has_perm('admin'): user = User.query.get(user_id) else: user = self.request.user res = dict(status='error', msg='', file={}) if self.request.method == 'POST': file = self.request.POST['file'] data = self._upload_data(file.file.read()) size = len(data) mimetype = mimetypes.guess_type(file.filename)[0] if size and mimetype[:5] == 'image': data = h.image_resize(data, 's', 100, 100) self._file_write(_avatar_path(user.id, self.request.registry.settings, True), data) res['status'] = 'ok' res['file'] = { 'url': self.request.url_for('/user/avatar_temp', user_id=user.id), 'filename':file.filename, 'mime':mimetype, 'size':size } return res