示例#1
0
 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
示例#2
0
 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
示例#3
0
 def post(self, request):# pylint: disable=no-self-use
     """The name property of the file which is passed is 'icon', so in HTML form it must be set:
     <input type='file' name = 'icon'>
     """
     try:
         if request.FILES:
             pic = request.FILES['icon']
             while not AwsService.check_if_in_bucket(pic):
                 pic.name = AwsService.change_filename(pic)
             if AwsService.upload(pic):
                 url = AwsService.get_image_url(pic)
                 return HttpResponse(url, status=201)
             return RESPONSE_500_NO_SUCCESS
         return RESPONSE_400_UPLOAD_ERROR
     except datastructures.MultiValueDictKeyError:
         return RESPONSE_400_NO_FILE