Cordova FileTransfer发送文件但没有收到任何内容 [英] Cordova FileTransfer sends file but nothing received

查看:188
本文介绍了Cordova FileTransfer发送文件但没有收到任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发送的视频是通过Cordova的



这是我的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(错误);
},
期权,

);

(注意最后一个参数, trustAllHosts ,已设置因为我的测试服务器是自签名的,所以是真的。)



Cordova显然认为它是发送数据,但我的PHP脚本不同意。这是我的PHP:

  file_put_contents(
'readout.txt',
Payload \ n- --------- \ n。
file_get_contents('php:// input')。
\ n \\\
nRequest \\\
------- --- \ n。
print_r($ _ REQUEST,1)。
\ n\\\
Files\\\
---------- \ n。
print_r($ _ FILES,1)。
\ n\\\
Post \ n ---------- \ n。
print_r($ _ POST,1 )
);

正如你所看到的,我几乎无处不在。所有这些都导致空读数,但是, readout.txt



我做错了什么?

解决方案

原来 chunkedMode param (在选项中)是罪魁祸首。



如果这对其他人有帮助,请禁用此功能(默认情况下为真),一切都应该没问题。

  options.chunkedMode = false; 

不知道如何解释空请求的行为。该param用于以块的形式发送文件,以允许某种进度反馈。


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. 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)

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.)

Cordova clearly thinks it's sent data, but my PHP script disagrees. Here's my 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.

What am I doing wrong?

解决方案

It turned out the chunkedMode param (in options) was the culprit.

In case this helps anyone else, disable this (it's true by default) and all should be fine.

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.

这篇关于Cordova FileTransfer发送文件但没有收到任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆