def takeImage(request): if request.method == "GET": return render(request, 'Image/Upload.html') else: image = request.FILES['emo-image'] emo_image = Image(user=request.user, Image_url=image) emo_image.save() return redirect('filterImage')
def clickimage(request): if request.method == 'POST': # if request.user: # data = dict(request.POST) # img = data['img'][0] # if img is None: # print("It is None") # else: # print("Successful request") # print(data) # print(request.POST) data = dict(request.POST)['img'][0] # print(img_base64) # img = base64.b64decode(img_base64) # print(img) # Check if the base64 string is in the "data:" format if 'data:' in data and ';base64,' in data: # Break out the header from the base64 content header, data = data.split(';base64,') # Try to decode the file. Return validation error if it fails. try: decoded_file = base64.b64decode(data) except TypeError: TypeError('invalid_image') # Generate file name: # n = 0 # if Image.objects.last(): # n = Image.objects.last().id # 12 characters are more than enough. # Get the file name extension: name = str(request.user.username) + str(uuid.uuid4())[:6] + ".jpeg" # complete_file_name = "%s.%s" % (file_name, file_extension,) file = ContentFile(decoded_file, name=name) img = Image(user=request.user, frame_image=file, name=name) img.save() path = '../media/images/' + name while Path(path) is None: i = i + 1 if i == 100: return JsonResponse({'text': "Image was not saved"}) # ans = pic(path) # img.verdict = ans if len(Image.objects.all()) % 10 == 0: return results(request) # return JsonResponse({'text': "Got the image"})
def get(r): album = r.d.album # type: Album image_num = r.d.image_num return Image.get_tokens(action=ImageUploadAction.ALBUM, num=image_num, album_id=album.res_id)
def post(r): qn_res_manager.auth_callback(r) action = r.d.action # type:str color_average = r.d.color_average['RGB'] # type: str image_info = r.d.image_info if 'orientation' in image_info: try: orientation = image_info['orientation'].upper().split('-') orientation = Image.orientation_str2int(orientation) except Exception: orientation = 1 else: orientation = 1 width, height = image_info['width'], image_info['height'] album = None if action in [ImageUploadAction.ALBUM, ImageUploadAction.ALBUM_COVER]: album = r.d.album # type: Optional[Album] image = Image.create( **r.d.dict('key', 'mime_type'), color_average=color_average, width=width, height=height, orientation=orientation, album=album, ) if action == ImageUploadAction.SPACEMAN: spaceman = r.d.spaceman spaceman.set_avatar(image) return image.d_base() elif action == ImageUploadAction.ALBUM_COVER: album.set_cover(image) return album.d_image() elif action == ImageUploadAction.MILESTONE: milestone = r.d.milestone milestone.set_cover(image) return image.d_base() return image.d()
def get(request): """ GET /api/image/history 获取历史图片 """ end = request.d.end count = request.d.count image_list = Image.get_old_images(end, count) if end == -1: image_list['image_list'] += MLC_IMG_LIST image_list['count'] += MLC_IMG_COUNT return response(body=image_list)
def post(request): """ POST /api/image/ 七牛上传用户头像回调函数 """ deprint('ImageView-post') ret = QN_PUBLIC_MANAGER.qiniu_auth_callback(request) if ret.error is not Error.OK: return error_response(ret) key = request.d.key ret = Image.create(key) if ret.error is not Error.OK: return error_response(ret) o_image = ret.body if not isinstance(o_image, Image): return error_response(Error.STRANGE) return response(body=o_image.to_dict())
def post(self, request, *args, **kwargs): default_value = { 'caption': request.POST['caption'], 'key1': request.POST['key1'], 'msg': request.POST['msg'], } error = validate_form(request.POST, request.FILES) if error == {}: photo = Image() photo.caption = request.POST['caption'] photo.image = request.FILES['image'] photo.save(**{ 'key': request.POST['key1'], 'msg': request.POST['msg'] }) default_value = {} queryset = Image.objects.all() page = request.GET.get('page', 1) photos = self.get_photos(queryset, page) context = dict(default_value, **dict(error, **{'objects': photos})) return render(request, "index.html", context)
def get_image_token(self): return Image.get_token( action=ImageUploadAction.ALBUM_COVER, album_id=self.res_id, )
def get_image_token(self): return Image.get_token(action=ImageUploadAction.MILESTONE, mid=self.pk)
def get_avatar_token(self): return Image.get_token( action=ImageUploadAction.SPACEMAN, space_user=self.get_union(), )