BulmerCloud / MapGame

This is a game the Map Game Dev team has been working on!

Home Page:https://mapgame.ddns.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Save Map button not working

DylanBulmer opened this issue · comments

Currently the button is visible, and runs a JavaScript function when clicked.

Bug in function:
When running the function, the canvas data URL is captured and sent in a form using AJAX. The AJAX does send the form to the server, but the server throws a 400 error saying it didn't get anything.

Server Code:

@app.route('/game/<id>', methods=["POST", "GET"])
def serveGameUpdate(id):
    if request.method == "POST":
        print('Getting Data')
        data = request.form['map']
        FileStorage(stream=data).save(SERVER+id, id+'.png')
        return 'ok'

Client Code:

save: function() {
    let img = game.map.canvas.toDataURL("image/png")
    let form = new FormData;
    form.append('map', img);
    form.append('id', data.id);
    let ajax = new XMLHttpRequest();
    ajax.open("POST",window.location.href);
    ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    ajax.send(form);
}

Put on standby for the time being. I plan on making this feature use a web socket instead.