Qml上传文件(路径)

时间:2018-06-10 08:48:36

标签: javascript upload qml

我有一个纯qml应用程序,我想上传一个文件(图像)与xmlhttprequest与qml的javascript实现。我有一个文件选择器,我将路径作为字符串,但我现在如何才能正确上传文件?

function upload ( path, callback ) {

        // Send the file to the server
        var requestUrl = "https://matrix.org/_matrix/media/r0/upload"
        var http = new XMLHttpRequest();
        http.open( "POST", requestUrl, true);
        http.setRequestHeader('Authorization', 'Bearer ' + token);
        http.onreadystatechange = function() {
            if ( http.readyState === XMLHttpRequest.DONE ) {
                callback ( JSON.parse(http.responseText) )
            }
        }

        // This does not work :-(
        http.send ( path )
}

1 个答案:

答案 0 :(得分:-3)

this寻求帮助(mozilla):

使用此选项检查是否在服务器端发送任何数据(PHP)(Mozilla示例)

<?php
/* register.php */
header("Content-type: text/plain");
/*
NOTE: You should never use `print_r()` in production scripts, or
otherwise output client-submitted data without sanitizing it first.
Failing to sanitize can lead to cross-site scripting vulnerabilities.
*/
echo ":: data received via GET ::\n\n";
print_r($_GET);
echo "\n\n:: Data received via POST ::\n\n";
print_r($_POST);
echo "\n\n:: Data received as \"raw\" (text/plain encoding) ::\n\n";
if (isset($HTTP_RAW_POST_DATA)) { echo $HTTP_RAW_POST_DATA; }
echo "\n\n:: Files received ::\n\n";
print_r($_FILES);
?>