Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Shrimpey304 opened this issue Feb 5, 2025 · 3 comments

Comments

@Shrimpey304
Copy link

Shrimpey304 commented Feb 5, 2025

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`
@N-o-X
Copy link

N-o-X commented Feb 6, 2025

Hey @Shrimpey304,

could you provide us with any details on what exactly is going wrong? Any response codes or bodies are highly appreciated. It would also help if you could tell me what headers are included in headerwithtoken = await self.getHeaderType(3).

Besides that I don't notice anything specific that's wrong here.

@Shrimpey304
Copy link
Author

Shrimpey304 commented Feb 6, 2025

Hello @N-o-X

These are the headers being used in the calls, it sets the token from the fileserver to the "token" dict.

`

    if typenumber == 2:
        headersuploadtype : dict = {
            "Authorization": f'Bearer {constants.NITRADO_KEY}',
            "Content-Type": "application/json"}
        return headersuploadtype
    
    if typenumber == 3:
        headersuploadWithToken : dict = {
            "token" : None,
            "Authorization": f'Bearer {constants.NITRADO_KEY}',
            "Content-Type": "application/json"}
        return headersuploadWithToken

`

These are the responses im getting from all the calls, including downloading the banfile content beforehand which works fine. ive modified the banfiles content by adding the gamertags i want to ban at the end, then pass that as the banlistContent parameter. It gives back created and ok when calling the upload endpoint.

`

calls to the download api endpoint
<ClientResponse(https://api.nitrado.net/services/13952670/gameservers/file_server/download?file=/games/ni9580479_4/noftp/dayzps/ban.txt) [200 OK]>
<CIMultiDictProxy('Date': 'Thu, 06 Feb 2025 18:29:42 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Vary': 'Accept-Encoding', 'x-frame-options': 'SAMEORIGIN', 'x-xss-protection': '1; mode=block', 'x-content-type-options': 'nosniff', 'x-download-options': 'noopen', 'x-permitted-cross-domain-policies': 'none', 'referrer-policy': 'strict-origin-when-cross-origin', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'POST, GET, PUT, DELETE, OPTIONS', 'Access-Control-Allow-Headers': 'Authorization, Auth, Content-Type, X-Nitrapi-Version, X-MSAPP-Version', 'x-client-id': '111', 'x-user-id': '9580479', 'x-ratelimit-limit': '15000', 'x-ratelimit-remaining': '14914', 'x-ratelimit-reset': '1738870003', 'Etag': 'W/"a2015f3296249f6f6b073ac0c4a26ff1"', 'Cache-Control': 'max-age=0, private, must-revalidate', 'x-request-id': '8737c2a269963a11dc96e6d308117e5c', 'x-runtime': '0.016591', 'strict-transport-security': 'max-age=31536000; includeSubDomains', 'Content-Encoding': 'gzip', 'cf-cache-status': 'DYNAMIC', 'Server': 'cloudflare', 'CF-RAY': '90dd3509b9a22445-AMS', 'alt-svc': 'h3=":443"; ma=86400')>

#downloads banfile from fileserver
<ClientResponse(https://fileserver.nitrado.net/ms2456/download/?token=6801659e-2d7f-4384-8a9c-21041228a51e) [200 OK]>
<CIMultiDictProxy('Server': 'nginx/1.10.3', 'Date': 'Thu, 06 Feb 2025 18:29:42 GMT', 'Content-Type': 'application/octet-stream', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET, OPTIONS', 'Access-Control-Allow-Headers': 'Content-Range, Content-Disposition, Content-Type, Authorization, X-Requested-With, Cache-Control, Accept, Origin, X-Session-ID, Token', 'Access-Control-Max-Age': '86400', 'Access-Control-Allow-Credentials': 'false', 'Content-Disposition': 'attachment; filename="ban.txt"')>

#modifies the banlist content in between these requests

#calls upload endpoint -- first call to makeRequest() in the function above
<ClientResponse(https://api.nitrado.net/services/13952670/gameservers/file_server/upload?path=/games/ni9580479_4/noftp/dayzps/&file=ban.txt) [201 Created]>
<CIMultiDictProxy('Date': 'Thu, 06 Feb 2025 18:29:42 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'x-frame-options': 'SAMEORIGIN', 'x-xss-protection': '1; mode=block', 'x-content-type-options': 'nosniff', 'x-download-options': 'noopen', 'x-permitted-cross-domain-policies': 'none', 'referrer-policy': 'strict-origin-when-cross-origin', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods':
'POST, GET, PUT, DELETE, OPTIONS', 'Access-Control-Allow-Headers': 'Authorization, Auth, Content-Type, X-Nitrapi-Version, X-MSAPP-Version', 'x-client-id': '111', 'x-user-id': '9580479', 'x-ratelimit-limit': '15000', 'x-ratelimit-remaining': '14912', 'x-ratelimit-reset': '1738870003', 'Etag': 'W/"1d62b480d3376ee4e71e6f73f8a0be44"', 'Cache-Control': 'max-age=0, private, must-revalidate', 'x-request-id': '64bc7e77f986d48bd39fcd8cc21fcab6', 'x-runtime': '0.100312', 'strict-transport-security': 'max-age=31536000; includeSubDomains', 'cf-cache-status': 'DYNAMIC', 'Server': 'cloudflare', 'CF-RAY': '90dd350bea16b8b2-AMS', 'alt-svc': 'h3=":443"; ma=86400')>

#should upload file to fileserver, but simply does not upload the file. -- second call to makeRequest() in the function above
{'status': 'success', 'data': {'token': {'url': 'https://fileserver.nitrado.net/ms2456/upload/', 'token': '845da32e-5a0e-4136-81f8-27932c8668d8'}}}
<ClientResponse(https://fileserver.nitrado.net/ms2456/upload/) [200 OK]>
<CIMultiDictProxy('Server': 'nginx/1.10.3', 'Date': 'Thu, 06 Feb 2025 18:29:42 GMT', 'Content-Type': 'text/html; charset=UTF-8', 'Content-Length': '0', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'POST, OPTIONS', 'Access-Control-Allow-Headers': 'Content-Range, Content-Disposition, Content-Type, Authorization, X-Requested-With, Cache-Control, Accept, Origin, X-Session-ID, Token', 'Access-Control-Max-Age': '86400', 'Access-Control-Allow-Credentials': 'false')>

`

We have tried using different content types and header layouts, but all result either in a Bad request error or a 200 OK with the same n, but when we look in the Nitrado WebInterface it has not updated anything from the banlist. let me know if you need any more info on the program.

(excuse the formatting of the message)

@Shrimpey304
Copy link
Author

We have found out the upload endpoint is working as we do see the banfile's filesize change when we list the directory. Only after a few seconds its being reset to the old banlist, and it never updates in the webinterface. Is there something we are missing on that end?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants