Send video file via curl and store it as a BlobMedia

Hey folks! :slight_smile:

What I’m trying to do:

  1. Sending an existing .mp4 file from my Google Colab to my anvil endpoint via curl
  2. Grab the get_bytes(), create a BlobMedia object and store it in a media table
  3. Download the video file from the media table directly (this fails)

What I’ve tried and what’s not working:
I tried many approaches, but what still does not work is: the file seems to be corrupt if I download it from the media table.

Code Sample:

# on Google Colab
@anvil.server.http_endpoint('/update_video')
def sendVideoData(**q):
  returnValue = !curl -X POST -H "Content-Type: video/mp4" -F 'video=@video.mp4' https://YRTYBNHX5VIVWH3L.anvil.app/_/private_api/XYZ/updatevideo
  print(returnValue)
  return
# on Anvil (Server Module)
@anvil.server.http_endpoint('/updatevideo', 
                            methods=["POST"], authenticate_users=False)
def update_video(**q):
  multipart_bytes = anvil.server.request.body["data"].get_bytes()
  videoBlobMedia = anvil.BlobMedia(content_type="video/mp4", content=multipart_bytes, name="video10.mp4")
  app_tables.videos.add_row(Video=videoBlobMedia)
  return anvil.server.HttpResponse(201)

Result: when I try to download the successfully saved file from the database, the .mp4 seems to be corrupt.

Any help is appreciated! :+1:

Hi @divyeshlakhotia thanks for your first try, yes I think, too, you misunderstood my question at first glance, but I appreciate you even tried! and cared about it :slight_smile:

Sure, no problem. I have never tried Google colab API so perhaps someone who has can help better

@divyeshlakhotia thanks. I need to say it’s not a Google colab issue itself. I manage successfully to send base64 blobs in requests successfully to my anvil app, but I struggle with sending media files (like .mp4) and then convert them back again to .mp4.
It arrives and can be saved in my anvil app, but as soon as I try to fetch this media entry from the database, I can’t “use” the .mp4 file because it seems to be corrupt. It downloads the data (size seems to match), but it’s not playable.