0

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

$ curl -F "[email protected]" 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'}

2
  • this page can conver curl to python and other languages: curl.trillworks.com Commented Jul 24, 2019 at 11:55
  • why do you encode file ? Send it as normal data. Commented Jul 24, 2019 at 11:56

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, the thing was easier than I thought
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())

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.