0

I'm trying to download a stored file on file.io, but the problem is that I get a 2kb file. How can I download it? When opening the link in the browser I get the download window. Here there is the code I'm using.

url = "https://www.file.io/"
r = requests.get(url, allow_redirects=True)
filename = "filedownloaded"
open(filename, 'wb').write(r.content)
martineau
  • 119,623
  • 25
  • 170
  • 301
IceFire
  • 33
  • 1
  • 6

1 Answers1

1

file.io has an api for cURL that is very easy to use.

You need to know the target file extension and one time url. For example if I upload a png to file.io this would be my cURL request and the file will be downloaded in the current directory.

curl -o test.png https://file.io/fileURL

Since you are writing a script for this I am assuming that you will have this information.

import os
directory = "cd /target/directory/"
curlReq = "curl -o "
#you will have to retrive the info for these variables
filename = "filename.extension "
url = "https://file.io/uniqueURL"

os.system(directory)
os.system(curlReq + filename + url)

I there might be other ways but this worked for me.

EDIT: cURL request using subprocess.

from subprocess import call

url = "https://file.io/uniqueURL"
filename = "filename.extension"
call(["cd","/target/directory/"])
call(["curl","-o",filename,url])
Zach
  • 93
  • 6
  • 1
    An API _for cURL_ ? Also, why use `os.system()` instead of the subprocess module, the latter of which is recommend by the docs for the former? – AMC Mar 11 '20 at 23:32
  • 1
    @AMC I edited my post to include the subprocess module. What is the benefit of this over os? – Zach Mar 12 '20 at 00:19
  • 1
    You can find some information on the subject [here](https://stackoverflow.com/questions/4813238/difference-between-subprocess-popen-and-os-system) and [here](https://docs.python.org/3/library/os.html#os.system). :) – AMC Mar 12 '20 at 00:28