使用Phonegap将图片发送到服务器

时间:2013-02-19 10:48:42

标签: android ios cordova

我想将图片发送到我的服务器。这是我的代码如下。我想为每张照片发送参数。我的问题是,如果我更改以下行fileSystem.root.getFile ("readme.txt",...,则fileSystem.root.getFile ("/ mnt / sdcard / Byza / readme.txt",...代码将无效。以及如何使用文件

发送参数
function test()
        {
            //window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail);
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
                function(fileSystem)//On success find the file, we called to this Function.
                {
                   fileSystem.root.getFile("readme.txt", {create: false, exclusive: false}, 
                                           function(fileEntry)
                                           {
                                                  var options = new FileUploadOptions();
                                                  options.fileName='readme.txt';  //The file name you want the file to be saved as on the server. If not set defaults to "image.jpg". (DOMString)
                                                  var params = {};
                                                  params.IdPrestation = "IdPrestation";
                                                  params.IdPhoto        = "IdPhoto";
                                                 options.params = params;

                                                  var ft = new FileTransfer();

                                                           ft.upload(fileEntry.toURL(),'http://loco.bluelinecity.com/upload.php',function(r)
                                                           {                   //toURL():: Retourne une URL qui peut être utilisée pour localiser un répertoire
                                                           navigator.notification.alert(r.response,function(){});
                                                           },
                                                           function(e)
                                                           {
                                                           navigator.notification.alert('Server Error:' + e.code,function(){});             
                                                           },
                                                           options
                                                           );//ft.upload
                                            },

                                            function(e)
                                            {
                                            navigator.notification.alert("File Create Error" + e,function(){});
                                            }
                                            );//Fin Get File Systeme

                 }//Fin function(fileSystem)

                 ,function(e)//On Error find the file, we called to this Function.
                 {
                   navigator.notification.alert("File request Error" + e);
                 }
                 );//Request File System

        }//Fin test

0 个答案:

没有答案
相关问题