简体   繁体   English

Cordova FileTransfer发送文件,但未收到任何内容

[英]Cordova FileTransfer sends file but nothing received

I'm sending a video recorded via Cordova's MediaCapture plugin to a remote server via the FileTransfer plugin , but nothing - neither the file, nor any data whatsoever - is arriving at the server end. 我正在将通过Cordova的MediaCapture插件记录的视频通过FileTransfer插件发送到远程服务器,但是没有任何东西-文件或任何数据都没有到达服务器端。 The server receives the request, but it seems to be empty. 服务器接收到该请求,但该请求似乎为空。

According to Cordova, everything goes fine. 据科尔多瓦说,一切顺利。 Here's the readout from the success callback: 这是成功回调的结果:

在此处输入图片说明

And here's my JS: ( mediaFiles[0] is the captured video file) 这是我的JS :( mediaFiles[0]是捕获的视频文件)

var options = new FileUploadOptions();
options.fileName = 'foo.bar';
options.mimeType = mediaFiles[0].type;
options.params = {
    mime: mediaFiles[0].type
};

var ft = new FileTransfer();
ft.upload(
    mediaFiles[0].fullPath,
    encodeURI("http://xxxxxx.com/receive-video.php"),
    function (r) {
        console.log(r);
        alert('sent file!');
    },
    function (error) {
        alert('error');
        console.log(error);
    },
    options,
    true
);

(Note the last param, trustAllHosts , is set to true since my test server is self-signed.) (请注意,由于我的测试服务器是自签名的,因此最后一个参数trustAllHosts设置为true。)

Cordova clearly thinks it's sent data, but my PHP script disagrees. 科尔多瓦显然认为这是发送数据,但是我的PHP脚本不同意。 Here's my PHP: 这是我的PHP:

file_put_contents(
    'readout.txt',
    "Payload\n----------\n".
    file_get_contents('php://input').
    "\n\nRequest\n----------\n".
    print_r($_REQUEST, 1).
    "\n\nFiles\n----------\n".
    print_r($_FILES, 1).
    "\n\nPost\n----------\n".
    print_r($_POST, 1)
);

As you can see, I'm looking pretty much everywhere. 如您所见,我到处都在寻找。 All these result in empty readouts, however, in readout.txt . 所有这些都会导致在readout.txt中显示为空的读数。

What am I doing wrong? 我究竟做错了什么?

It turned out the chunkedMode param (in options ) was the culprit. 事实证明, chunkedMode参数 (在options )是罪魁祸首。

In case this helps anyone else, disable this (it's true by default) and all should be fine. 万一这对其他人有帮助,请禁用此功能(默认情况下为true),一切都很好。

options.chunkedMode = false;

Not sure how to explain the behaviour of the empty request with it turned on, though. 但是,不确定如何打开它来解释空请求的行为。 The param exists to send the file in chunks, to allow for progress feedback of some sort. 存在该参数以分块发送文件,以允许某种进度反馈。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM