Change in BLOB media url?

Hi! :slight_smile:

I have an app that sends an image url (image stored in a datatable) to and API. This API returns the image but with the background removed.

Its been working like magic ever since I started using it. But this weekend for some reason it stopped working. No changes from me. The API sent back this error:

Error: 400 {"errors":[{"title":"Failed to download image from given image_url: HTTP Status 400","code":"failed_image_download"}]}

has anything changed in the way that .url works?

Many thanks!

Hi @michaellavers,

Are you calling the API from a background or scheduled task, the Uplink, or a server function called directly from the browser?

In the meantime while we investigate, you can return the image from an HTTP endpoint as a work-around.

Hi brooke, as a workaround I have used the APIs alternative which is sending the getbytes() to their API and thats working fine.

But previously…

I was calling the API from a server function: (shown below)

remove_bg_key = anvil.secrets.get_secret("remove_bg")

@anvil.server.callable
def remove_background(new_image_url, new_image_name, image_type='product', image_crop=True):
  image_filename = new_image_name + "_masked.png"
  response = requests.post(
    'https://api.remove.bg/v1.0/removebg',
    data={
        'image_url': new_image_url,
        'size': 'full', 
        'type' : image_type, 
        'crop': image_crop
    },
    headers={'X-Api-Key': remove_bg_key},
  )
  if response.status_code == requests.codes.ok:

    my_media = anvil.BlobMedia(content_type="image/png", content=response.content, name=image_filename)
    return my_media
  else:
    print("Error:", response.status_code, response.text)

Like I said, it was fast and dandy until this weekend. Just wondered if there was an update on blob media or ‘summink’ like that.

Warm regards,

Michael

Hi @michaellavers,

There were indeed a few changes to Media URLs, but what you’re doing should still work! Please could you also share the code that calls this server function? In particular, how is the value of new_image_url generated, and from what Media object?

Thanks!

Hi Ian!

of course! :slight_smile:

  def proceed_with_mask_click(self, **event_args):
    """This method is called when the button is clicked"""
    
    app_tables.butler_variables.get(name="mask_single")['media'] = self.upload.file
    # print(app_tables.butler_variables.get(name="mask_single")['media'].url)
    
    new_image_url = app_tables.butler_variables.get(name="mask_single")['media'].url  
    new_image_name = (app_tables.butler_variables.get(name="mask_single")['media'].name).split(".")[0]
    butler_variables_name = "mask_single"
    
    if self.this_is_a_person_q.checked == True:
      new_image_type = "person"
    else:
      new_image_type = "product"
      
      
      
    if self.crop_image_q.checked == True:
      image_crop = True
    else:
      image_crop = False
    
    app_tables.butler_variables.get(name="returned_image")['media'] = anvil.server.call_s('remove_background', new_image_url, new_image_name, new_image_type, image_crop)
   
    
    
    
    
    self.image_1.source = app_tables.butler_variables.get(name="returned_image")['media']
    
    if self.auto_download_q.checked == True:
      anvil.media.download(app_tables.butler_variables.get(name="returned_image")['media'])