GoFile-API
Um eine Datei auf gofile.io hochzuladen, müssen Sie multipart / form-data verwenden.
from requests_toolbelt . multipart . encoder import MultipartEncoder
import aiohttp
import asyncio
import sys
import requests
async def encode_file ( name : str ) -> dict :
mp_encoder = MultipartEncoder (
fields = {
'filesUploaded' : ( name , open ( name , 'rb' ))
}
)
return mp_encoder
async def get_server () -> str :
url = "https://api.gofile.io/getServer"
async with aiohttp . ClientSession () as session :
async with session . get ( url ) as resp :
server = await resp . json ()
return server [ 'data' ][ 'server' ]
async def upload_server ( server : str ) -> dict :
try :
url = f"https:// { server } .gofile.io/uploadFile"
data_json = await encode_file ( "music.m4a" )
#Unable to send file using async methodologies like aiohttp, some kind of weird error happens
#It says the uploaded file format is incorrect
#I still don't have a solution for this.
#ERROR: Only io.IOBase, multidict and (name, file) pairs allowed, use .add_field() for passing more complex parameters
response = requests . post (
url ,
data = data_json ,
headers = { 'Content-Type' : data_json . content_type }
)
return response . json ()
except Exception as e :
trace_back = sys . exc_info ()[ 2 ]
line = trace_back . tb_lineno
print ( f"ERROR UPLOAD -> { e } | { line } " )
async def main () -> None :
server_get = await get_server ()
response = await upload_server ( server = server_get )
print ( 'LINK: ' , response [ 'data' ][ 'downloadPage' ])
asyncio . run ( main ())
method GET
https://apiv2.gofile.io/getServer
Gibt den besten verfügbaren Server zum Empfangen von Uploads zurück. Antwortbeispiel
{"status":"ok","data":{"server":"srv-file9"}}
Beispiel in Python
from requests_toolbelt . multipart . encoder import MultipartEncoder
import requests
import json
mp_encoder = MultipartEncoder (
fields = {
'filesUploaded' : ( 'file_name.txt' , open ( 'file_name.txt' , 'rb' ))
}
)
r = requests . post (
'https://srv-file9.gofile.io/upload' ,
data = mp_encoder ,
headers = { 'Content-Type' : mp_encoder . content_type }
)
scrap = r . json ()
#send "Token file" 123Abc
Token = scrap [ 'data' ][ 'code' ]
Antwortbeispiel
{"status":"ok","data":{"code":"123Abc","removalCode":"3ZcBq12nTgb4cbSwJVYY"}}
Ihr Zugangslink sieht folgendermaßen aus: https://gofile.io/?c=123Abc
Um die Datei zu validieren und den direkten Link zu erhalten, müssen Sie Ihr Token auf dem Server validieren, indem Sie ihm Ihr Token senden
Beispiel in Python
import requests
session = requests . Session ()
sendToken = 'https://apiv2.gofile.io/getServer?c={}' . format ( Token )
validating = 'https://srv-file9.gofile.io/getUpload?c={}' . format ( Token )
headers = { 'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36 OPR/67.0.3575.137' }
session . get ( sendToken , headers = headers )
session . get ( validating , headers = headers )
r = 'https://srv-file9.gofile.io/download/{}/file_name.txt' . format ( Token )
Ihr Zugangslink sieht folgendermaßen aus: https://srv-file9.gofile.io/download/123Abc/file_name.txt