Skip to content

Unable to upload file via https://api.nitrado.net/services/:id/gameservers/file_server/upload #24

@Shrimpey304

Description

@Shrimpey304

I have been trying to upload a ban.txt file via the upload endpoint, which gives me back a fileserver link and token. I seem to be unable to find out what this url expects from me, any reachout to support just sends me to the documentation which is lacking any usefull info and/or out of date. I would like to know what i have to do to actually upload the file. I will provide my function (python) below for added info.
`

async def apiUploadBanFile(self, serviceID : str, username : str, banlistContent : str) -> bool:
    try:
        platform : str = await self.apiGetServicePlatform(serviceID)
        filePath = f"/games/{username}/noftp/{platform}/"
        with open("tempfolder/ban.txt", 'w') as file:
            file.write(banlistContent)

        uploadUrl = f"{constants.NITRADO_API_BASE}/services/{serviceID}/gameservers/file_server/upload"
        uploadParams = {"path": filePath, "file" : "ban.txt"}

        request: dict = await self.makeRequest(
            method="POST", 
            url=uploadUrl, 
            headers=await self.getHeaderType(2), 
            params=uploadParams
        )
        print(request)

        headerwithtoken = await self.getHeaderType(3)
        data: dict = request.get("data", {})
        info: dict = data.get("token", {})
        fileserverUrl: str = info.get("url")
        token : str = info.get("token")
        headerwithtoken["token"] = token

        with open("tempfolder/ban.txt", 'rb') as uploadThis2:
            data = uploadThis2.read()
            uploadResponse = await self.makeRequest(   #makes the request to the fileserver url and has the token in header
                method="POST",
                url=fileserverUrl,
                headers=headerwithtoken,
                data=data
            )
        return uploadResponse.get("status", "") == "success"
    
    except Exception as e:
        self.logger.error(f"Failed to upload ban list for service {serviceID}: {e}")
        return False`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions