def delete(self, request):# pylint: disable=no-self-use """the method must accept the name of the file (string) of the image which is already used as a profile photo or icon """ key = request.body.decode() if not AwsService.check_if_in_bucket(key): if AwsService.del_photo(key): return RESPONSE_200_SUCCESS return RESPONSE_500_NO_SUCCESS return RESPONSE_404_NOT_FOUND
def put(self, request):# pylint: disable=no-self-use """The method must accept the name of the file (string) of the image which is already used as a profile photo, and the new image which is passed in a form. The name property of the file which is passed is 'icon', the name of the file to be replaced is 'old', so in HTML form it must be set: <input type='file' name = 'icon'> """ request.method = 'POST' req_dict = request.POST old_file = req_dict['old'] new_file = request.FILES['icon'] if AwsService.upload(new_file): if AwsService.del_photo(old_file): if not AwsService.check_if_in_bucket(new_file): return RESPONSE_200_SUCCESS return RESPONSE_404_NOT_FOUND return RESPONSE_500_NO_SUCCESS