Forum

need shot function in screen module to not download

25 July 2017 06:53
Hi, Is there a way to stop the shot function from screen module from automatically downloading the screenshot? I need it to send the screenshot back to the server, not download it to the user system.
25 July 2017 18:20
You might need to look for a solution with the back-end framework you are using.
For example, if you were using Node.js, here is a method for doing that.
26 July 2017 11:21
Hi, you can also look at the source code of the "shot" method. It utilizes the canvas_data_url function for getting the URL of the corresponding Blob object, which represents a screenshot data. This function accepts a callback, in which you can send the data to the server in two requests: one for getting the blob object from the URL parameter and another for sending it to the server.

function screenshot_to_server(format, quality) {
    format = format || "image/png";
    quality = quality || 1.0;

    var cb = function(url) {
        // getting the blob object from URL
        var xhr = new XMLHttpRequest();
        xhr.open("GET", url, true);
        xhr.responseType = "blob";
        xhr.onload = function(e) {
            if (this.status == 200) {
                var blob = this.response;

                // sending the data to the server
                var xhr = new XMLHttpRequest();
                xhr.open("POST", "URL_TO_MY_SERVER", true);
                xhr.send(blob);
                xhr.onload = function(e) {
                    if (this.status == 200) {
                        console.log("Uploaded successfully!");
                    }
                }
            }
        };
        xhr.send();
    }

    m_main.canvas_data_url(cb, format, quality, true);
}

- just replace "URL_TO_MY_SERVER" with a valid url address.
Blend4Web Team
 
Please register or log in to leave a reply.