0

我正在尝试将音频文件上传到服务器,但每次备用上传都会失败。

E/FileTransfer(10242): {"target":"http:\/\/abc:8080\/foldername\/foldername\/test.php?" , "source":"file:\/\/\/storage\/sdcard0\/voice.wav","code":3}
E/FileTransfer(10242): java.io.EOFException

我的代码:

var gotFileSystem = function(fileSystem) {
fileSystem.root.getDirectory(dirName, {
create : true
}, function(dataDir) {
fileURI = dataDir.fullPath;
fileURI = fileURI + '/' + fileName;
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = fileURI.substr(fileURI.lastIndexOf('/') + 1);
options.mimeType = fileMime;
$.mobile.showPageLoadingMsg();
var ft = new FileTransfer();
ft.upload(fileURI, encodeURI(url), win, fail, options);
$.mobile.hidePageLoadingMsg();
}, dirFail);
};
4

1 回答 1

0

而不是获取目录 (getDirectory) 直接使用 (getFile) 方法获取文件。

       var filePath =  "myfolder/myfile.mp3";
       var fileUploadURL = "fileUpload.jsp";

       window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,function(fs){
                     fs.root.getFile(filePath,{create: false, exclusive: false}, function(mediaFile){
                            var ft = new FileTransfer();
                            var fPath = mediaFile.fullPath;
                            var fName = mediaFile.name;

                            var options = new FileUploadOptions();
                                options.fileKey = "mediaFile";
                                options.fileName = fName; 
                                options.mimeType = "audio/mpeg";
                                ft.upload(fPath, fileUploadURL,
                                    function(result) {                                         
                                       console.log('Upload success: ' + result.responseCode);
                                       console.log(result.bytesSent + ' bytes sent');
                                      },
                                    function(error) { 
                                        console.log('Error uploading file ' + fPath + ': ' + error.code);
                                     },options);
                                ft.abort();

                     }, null);
                 } , null);

`

于 2013-10-23T07:31:48.523 回答