0

So I have this example from https://www.file.io/

$ curl -F "file=@test.txt" https://file.io

How do I use this in python? I tried this:

from requests import post
from urllib import request
from base64 import b64encode

with open('files/some_name.mp4', 'rb') as img:
                encoded_img = b64encode(img.read())
        r = post(url='https://file.io', data={'file' : encoded_img})
        r = r.json()
        print(r)

And got {'success': False, 'error': 400, 'message': 'Trouble uploading file'}

Jake
  • 330
  • 1
  • 3
  • 16

2 Answers2

1

Do not send the file in the data parameter. There is a files parameter, try using that.

file = {'file': ('image.mp4', encoded_img)}
r = post(url='https://file.io', files=file)

Check this if it works. also refer HERE

Nitin
  • 246
  • 1
  • 7
0

Using this portal https://curl.trillworks.com I got working code. I tested with some image.

import requests

files = {
    'file': ('test.txt', open('test.txt', 'rb')),
}

response = requests.post('https://file.io/', files=files)

pritn(response.json())
furas
  • 134,197
  • 12
  • 106
  • 148