PhoneGap .wav从iOS设备上传正在服务器上创建一个0k文件 [英] PhoneGap .wav upload from an iOS device is creating a 0k file on the server

查看:240
本文介绍了PhoneGap .wav从iOS设备上传正在服务器上创建一个0k文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用PhoneGap在iPhone上录制音频,然后将该音频发送到服务器。我使用PhoneGaps Media API进行录音,然后使用PhoneGap文件传输API将文件发送到服务器。

I am attempting to record audio on an iPhone using PhoneGap, then send that audio to a server. I am using PhoneGaps Media APIs to make the recording, then the PhoneGap file transfer API to send the file to the server.

我可以让录音很好,并播放它完美地工作。然而,当我尝试将其发送到服务器时,记录显示在服务器上,但它表示文件大小为0k。

I am able to make the recording just fine, and playing it back works perfectly. When I try to send it to the server, however, the recording shows up on the server but it says the file is 0k big.

我做了相当广泛的搜索关于这个问题,并发现有其他人有这个问题。例如: https://groups.google.com/forum/#!topic/ phonegap / zjzSs6JVokE

I've done fairly extensive searching on this issue and found others that have had this problem. For example: https://groups.google.com/forum/#!topic/phonegap/zjzSs6JVokE

   function win(r) {
        alert("Code = " + r.responseCode);
        alert("Response = " + r.response);
        alert("Sent = " + r.bytesSent);
    }

    function fail(error) {
        alert("An error has occurred: Code = " + error.code);
        console.log("upload error source " + error.source);
        console.log("upload error target " + error.target);
    }

    function upLoad() {
        var options = new FileUploadOptions();
        options.fileKey="file";
        options.fileName=myPath.substr(myPath.lastIndexOf('/')+1);
        options.mimeType="audio/wav";

        var params = new Object();

        var headers={'headerParam':'headerValue'};

        options.headers = headers;

        options.chunkedMode = false;

        var ft = new FileTransfer();
        ft.upload(encodeURI(myPath),  encodeURI("http://myserver.com/upload.php"), win, fail, options);

    }

这是服务器端的代码:

print_r($_FILES);
$new_image_name = "testFile.wav";
move_uploaded_file($_FILES["file"]["tmp_name"], "/var/www/wwwroot/recordings/".$new_image_name);

我认为这可能是一个问题,我发送.wav文件。当我发送文件,r.bytesSent通常显示大约200到400字节(不管文件的大小),所以看起来像文件的实际内容只是不被发送。

I think that this may be an issue with the fact that I am sending .wav files. When I send the file over, r.bytesSent usually shows about 200 to 400 bytes (regardless of the size of the file), so it seems like the actual content of the file just isn't being sent over.

我用一个简单的文本文件测试了上面的代码,它通过很好,所以我不认为这是一个权限或语法问题。我没有尝试这个与图像文件,但我不能想象它使我的发送很大的不同。

I have tested the above code with a simple text file and it goes through just fine, so I don't think it's a permissions or syntactical issue. I haven't tried this with image files, but I can't imagine it makes to much of a difference what I am sending.

有没有人成功? / p>

Has anyone done this successfully?

推荐答案

我设法在几天前解决这个问题。
这是关于问题示例中的myPath变量。
myPath不能是tmp文件夹以外的任何东西(临时文件夹phonegap /设备创建)
因此,当您尝试发送文件时,您肯定知道该文件的副本是在tmp文件夹。
所以,在ft.upload之前这样做:

I managed to solve this a few days ago. It's about the myPath variable in the question's example. myPath can't be anything other than the tmp folder (the temporary folder phonegap/device creates) So when you try to send a file, you know for sure a copy of that file was made in the tmp folder. So do this just before the ft.upload:

myPath = myPath.replace(myFolderPath, 'tmp');



在我的例子中myFolderPath是'Documents \media'。
文档路径是自定义创建的文件保存在您的设备上的位置。

In my case myFolderPath was 'Documents\media'. The Documents path is where the custom created files are kept on your device.

我希望这会保存所有访问的google搜索页面的用户:)

(这适用于phonegap 3.0.0)

I hope this saves people from all visited google search pages :)
(This worked for phonegap 3.0.0)

这篇关于PhoneGap .wav从iOS设备上传正在服务器上创建一个0k文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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