2013-04-01 4 views
3

Я пытаюсь запустить приложение phonegap на новом устройстве BlackBerry 10 (Z10), и у меня возникает проблема. В основном, я делаю снимок, и я хочу загрузить его на свой сервер с помощью FileTransfer, но FileTransfer завершится неудачно с FileTransferError.FILE_NOT_FOUND_ERR.BlackBerry 10, Camera и FILE_NOT_FOUND_ERR

Затем я попытался использовать метод window.resolveLocalFileSystemURI, и теперь у меня есть FileError.NOT_FOUND_ERR. Я предполагаю, что эти две ошибки связаны.

fileURI Я передаю к обоим из них является fileURI, что я вернусь из успеха обратного вызова navigator.camera.getPicture и выглядит примерно так:

file:///accounts/1000/shared/camera/IMG_00000037.jpg 

Я взял пример ежевика приложение из загрузка PhoneGap 2.5.0 и слегка модифицировали index.html воспроизвести проблему, которую я буду включать ниже:

<!DOCTYPE html> 
<!-- 
    Licensed to the Apache Software Foundation (ASF) under one 
    or more contributor license agreements. See the NOTICE file 
    distributed with this work for additional information 
    regarding copyright ownership. The ASF licenses this file 
    to you under the Apache License, Version 2.0 (the 
    "License"); you may not use this file except in compliance 
    with the License. You may obtain a copy of the License at 

    http://www.apache.org/licenses/LICENSE-2.0 

    Unless required by applicable law or agreed to in writing, 
    software distributed under the License is distributed on an 
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
    KIND, either express or implied. See the License for the 
    specific language governing permissions and limitations 
    under the License. 
--> 
<html> 
    <head>  
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
     <meta name="format-detection" content="telephone=no" /> 
     <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" /> 
     <title>Hello World</title> 

     <script type="text/javascript" charset="utf-8"> 

     // Called when a photo is successfully retrieved 
     // 
     function onPhotoURISuccess(imageURI, testFunction) { 
      // Uncomment to view the image file URI 
      console.log(imageURI); 

      // Get image handle 
      // 
      var image = document.getElementById('image'); 

      // Unhide image elements 
      // 
      image.style.display = 'block'; 

      // Show the captured photo 
      // The inline CSS rules are used to resize the image 
      // 
      image.src = imageURI; 

      // Run our test function 
      testFunction(imageURI); 
     } 

     // Called if something bad happens. 
     // 
     function onPhotoURIFail(message) { 
      alert('Failed because: ' + message); 
     } 

     // A button will call this function 
     // 
     function getPhoto(source, testFunction) { 
      // un-sandbox file system to access shared folder 
      blackberry.io.sandbox = false; 

      // Retrieve image file location from specified source 
      navigator.camera.getPicture(
       function(imageURI) { 
        onPhotoURISuccess(imageURI, testFunction); 
       }, 
       onPhotoURIFail, 
       { 
        quality: 50, 
        destinationType: Camera.DestinationType.FILE_URI, 
        sourceType: source, 
        correctOrientation: true, 
        saveToPhotoAlbum: true 
       } 
      ); 
     } 

     // Tests whether we can resolve the imageURI returned from navigator.camera.getPicture 
     // 
     function testResolveLocalFileSystemURI(imageURI) { 
      window.resolveLocalFileSystemURI(
       imageURI, 
       function (fileEntry) { 
        var message = "Resolved local file system URI: " + imageURI; 
        document.getElementById("span").innerHTML = message; 
        console.debug(message); 
        console.debug(fileInfo); 
       }, 
       function (error) { 
        var message = "Unable to resolve local file system URI: " + imageURI + " error: " + error.code; 
        document.getElementById("span").innerHTML = message; 
        console.error(message); 
        console.debug(error); 
        console.debug("resolve error source " + error.source); 
        console.debug("resolve error target " + error.target); 
       } 
      ); 
     } 

     // Tests whether we can upload the imageURI returned from navigator.camera.getPicture using a FileTransfer 
     // 
     function testFileTransferUpload(imageURI) { 

      // Create =the file upload options 
      var options = new FileUploadOptions(); 
      options.fileKey="file"; 
      options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1); 
      options.mimeType="image/jpeg"; 

      // Create the file transfer and upload 
      var ft = new FileTransfer(); 
      ft.upload(
       imageURI, 
       encodeURI("http://some.server.com/upload.php"), 
       function (r) { 
        var message = "Code: '" + r.responseCode + "'' Response: '" + r.response + "'' Sent: '" + r.bytesSent + "'"; 
        document.getElementById("span").innerHTML = message; 
        console.debug(message); 
       }, 
       function (error) { 
        var message = "Unable to upload: " + imageURI + " error: " + error.code; 
        document.getElementById("span").innerHTML = message; 
        console.error(message); 
        console.debug(error); 
        console.debug("upload error source " + error.source); 
        console.debug("upload error target " + error.target); 
       }, 
       options 
      ); 
     } 

     // Tests whether we can upload the imageURI returned from navigator.camera.getPicture using a FileTransfer 
     // 
     function testFileSystemGetFile(imageURI) { 
      window.requestFileSystem(
       LocalFileSystem.PERSISTENT, 
       0, 
       function (fileSystem) { 
        fileSystem.root.getFile(
         imageURI, 
         {create: false}, 
         function (fileEntry) { 
          var message = "Got file: " + imageURI; 
          document.getElementById("span").innerHTML = message; 
          console.debug(message); 
          console.debug(fileInfo); 
         }, 
         function (error) { 
          var message = "Unable to get file: " + imageURI + " error: " + error.code; 
          document.getElementById("span").innerHTML = message; 
          console.error(message); 
          console.debug(error); 
          console.debug("get file error source " + error.source); 
          console.debug("get file error target " + error.target); 
         } 
        ); 
       }, 
       function (error) { 
        var message = "Unable to get file system. error: " + error.code; 
        document.getElementById("span").innerHTML = message; 
        console.error(message); 
        console.debug(error); 
        console.debug("file system error source " + error.source); 
        console.debug("file system error target " + error.target); 
       } 
      ); 
     } 
     </script> 

    </head> 
    <body> 
     <script type="text/javascript" src="cordova-2.5.0.js"></script> 
     <button onclick="getPhoto(Camera.PictureSourceType.CAMERA, testResolveLocalFileSystemURI);">Capture Photo, Test Resolve Local File System URI</button> <br> 
     <button onclick="getPhoto(Camera.PictureSourceType.CAMERA, testFileTransferUpload);">Capture Photo, Test File Transfer Upload</button> <br> 
     <button onclick="getPhoto(Camera.PictureSourceType.CAMERA, testFileSystemGetFile);">Capture Photo, Test File System Get File</button> <br> 
     <img style="display:none;" id="image" width="100" height="100" src="" /> 
     <span id="span"></span> 
    </body> 
</html> 

Всякий раз, когда я запустить приложение и попытаться сделать снимок, я получаю:

Unable to resolve local file system URI... 

Почему не может быть FileTransfer или window.resolveLocalFileSystemURI найти файл, который возвращается из navigator.camera.getPicture? У меня есть стандартный config.xml из PhoneGap примера со всеми необходимыми функциями и правами доступа (по крайней мере, насколько я знаю)

Ниже мой config.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<!-- 
     Licensed to the Apache Software Foundation (ASF) under one 
     or more contributor license agreements. See the NOTICE file 
     distributed with this work for additional information 
     regarding copyright ownership. The ASF licenses this file 
     to you under the Apache License, Version 2.0 (the 
     "License"); you may not use this file except in compliance 
     with the License. You may obtain a copy of the License at 

     http://www.apache.org/licenses/LICENSE-2.0 

     Unless required by applicable law or agreed to in writing, 
     software distributed under the License is distributed on an 
     "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
     KIND, either express or implied. See the License for the 
     specific language governing permissions and limitations 
     under the License. 
--> 
<!-- 
    Widget Configuration Reference: 
    http://docs.blackberry.com/en/developers/deliverables/15274/ 
--> 

<widget xmlns="http://www.w3.org/ns/widgets" 
     xmlns:rim="http://www.blackberry.com/ns/widgets" 
    version="1.0.0.0" id="org.apache.cordova.example"> 

    <name>cordovaExample</name> 

    <author>Your Name Here</author> 

    <description> 
     A sample Apache Cordova application that responds to the deviceready event. 
    </description> 

    <license href="http://opensource.org/licenses/alphabetical"> 
    </license> 

    <!-- Cordova API --> 
    <feature id="blackberry.system" required="true" version="1.0.0.0" /> 
    <feature id="org.apache.cordova" required="true" version="1.0.0" /> 
    <feature id="blackberry.find" required="true" version="1.0.0.0" /> 
    <feature id="blackberry.identity" required="true" version="1.0.0.0" /> 
    <feature id="blackberry.identity.phone" required="true" version="1.0.0.0" /> 
    <feature id="blackberry.pim.Address" required="true" version="1.0.0.0" /> 
    <feature id="blackberry.pim.Contact" required="true" version="1.0.0.0" /> 
    <feature id="blackberry.io.file" required="true" version="1.0.0.0" /> 
    <feature id="blackberry.utils" required="true" version="1.0.0.0" /> 
    <feature id="blackberry.io.dir" required="true" version="1.0.0.0" /> 
    <feature id="blackberry.app" required="true" version="1.0.0.0" /> 
    <feature id="blackberry.app.event" required="true" version="1.0.0.0" /> 
    <feature id="blackberry.system.event" required="true" version="1.0.0.0"/> 
    <feature id="blackberry.widgetcache" required="true" version="1.0.0.0"/> 
    <feature id="blackberry.media.camera" /> 
    <feature id="blackberry.ui.dialog" /> 
    <feature id="blackberry.connection" /> 
    <feature id="blackberry.bbm.platform" /> 
    <feature id="blackberry.invoke.card" /> 
    <feature id="blackberry.pim.contacts" /> 
    <feature id="blackberry.ui.contextmenu" /> 
    <feature id="blackberry.io.filetransfer" /> 
    <feature id="blackberry.io" /> 
    <feature id="blackberry.invoke" /> 
    <feature id="blackberry.invoked" /> 
    <feature id="blackberry.push" /> 
    <feature id="blackberry.media.microphone" required="true" version="1.0.0.0"/> 

    <!-- Cordova API --> 
    <access subdomains="true" uri="file:///store/home" /> 
    <access subdomains="true" uri="file:///SDCard" /> 
    <access subdomains="true" uri="file:///accounts" /> 

    <!-- Expose access to all URIs, including the file and http protocols --> 
    <access subdomains="true" uri="*" /> 

    <icon rim:hover="false" src="res/icon/blackberry/icon-80.png" /> 
    <icon rim:hover="true" src="res/icon/blackberry/icon-80.png" /> 

    <rim:loadingScreen backgroundColor="#CFCFCF" 
        foregroundImage="res/screen/blackberry/screen-225.png" 
      onFirstLaunch="true"> 
    <rim:transitionEffect type="fadeOut" /> 
    </rim:loadingScreen> 

    <content src="index.html" /> 

    <rim:permissions> 
    <rim:permit>use_camera</rim:permit> 
    <rim:permit>read_device_identifying_information</rim:permit> 
    <rim:permit>access_shared</rim:permit> 
    <rim:permit>read_geolocation</rim:permit> 
    <rim:permit>record_audio</rim:permit> 
    <rim:permit>access_pimdomain_contacts</rim:permit> 
    </rim:permissions> 

</widget> 

Ниже мои плагины .xml:

<?xml version="1.0" encoding="UTF-8"?> 
<!-- 
     Licensed to the Apache Software Foundation (ASF) under one 
     or more contributor license agreements. See the NOTICE file 
     distributed with this work for additional information 
     regarding copyright ownership. The ASF licenses this file 
     to you under the Apache License, Version 2.0 (the 
     "License"); you may not use this file except in compliance 
     with the License. You may obtain a copy of the License at 

     http://www.apache.org/licenses/LICENSE-2.0 

     Unless required by applicable law or agreed to in writing, 
     software distributed under the License is distributed on an 
     "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
     KIND, either express or implied. See the License for the 
     specific language governing permissions and limitations 
     under the License. 
--> 
<plugins> 
    <plugin name="App"   value="org.apache.cordova.app.App"/> 
    <plugin name="Device"   value="org.apache.cordova.device.Device"/> 
    <plugin name="Camera"   value="org.apache.cordova.camera.Camera"/> 
    <plugin name="NetworkStatus" value="org.apache.cordova.network.Network"/> 
    <plugin name="Notification" value="org.apache.cordova.notification.Notification"/> 
    <plugin name="Accelerometer" value="org.apache.cordova.accelerometer.Accelerometer"/> 
    <plugin name="Geolocation" value="org.apache.cordova.geolocation.Geolocation"/> 
    <plugin name="File"   value="org.apache.cordova.file.FileManager"/> 
    <plugin name="FileTransfer" value="org.apache.cordova.http.FileTransfer"/> 
    <plugin name="Contacts"  value="org.apache.cordova.pim.Contact"/> 
    <plugin name="Capture"  value="org.apache.cordova.capture.MediaCapture"/> 
    <plugin name="Battery"  value="org.apache.cordova.battery.Battery"/> 
    <plugin name="Media"   value="org.apache.cordova.media.Media"/> 
    <plugin name="Globalization" value="org.apache.cordova.globalization.Globalization"/> 
</plugins> 

Действия по воспроизведению мой вопрос:

  1. Следуйте this руководство (с использованием т он BlackBerry 10 (QNX) шагов)
  2. заменить данный файл index.html с одним я предоставил
  3. заменить данный файл config.xml с тем, я обеспечил (изменения должны быть минимальными)
  4. отлаживать его устройство BB10 (я использую Z10)
  5. нажмите на «захват фото» кнопку, и если у вас есть удаленный веб-инспектор подключен, вы должны увидеть ошибки
+0

Я также разместил это на PhoneGap [группы] Google (https://groups.google.com/forum/#!topic/phonegap/SaORue5G06k) – niltz

+0

Как и в [форуме разработчиков Blackberry] (http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/window-resolveLocalFileSystemURI-returning-FileError-NOT-FOUND/td-p/2278313/page/2), который получил некоторые отзывы, и я обновил свой пример выше с предложениями, не повезло. – niltz

ответ

0

вы можете попробовать добавить, <access uri="file://accounts/" subdomains="ture"/> вместо «магазина/дома».

Редактировать: Кроме того, при работе с файловой системой вы должны установить режим песочницы в false, иначе у вас может не получиться доступ к указанному файлу.

blackberry.io.sandbox = false; 

Помимо этого, похоже, что у вас есть почти все, что вам нужно.

+1

Я попробовал ваше предложение, и до сих пор нет кубиков. Я обновил свой оригинальный пост и обновил параметры config.xml и index.html. Обратите внимание, что в файле отсутствует косая черта: /// и ошибочная истина. Я убедился, что это было правильно, когда я добавил их. – niltz

1

Звучит очень похоже на вопрос, который я видел здесь: https://github.com/blackberry/BB10-WebWorks-Framework/issues/536

Попробуйте уронить файл : // протокол, чтобы получить только: /счета/1000/Shared/камеры/IMG_00000037.jpg

+1

Это только изменяет ошибку на код 5 (ENCODING_ERR), что означает, что URI недопустим. –

2

Вам необходимо сделать как blackberry.io.sandbox = false;, так и удалить файл: // протокол, по крайней мере, с моим опытом доступа к файлам из файловой системы. Кроме того, вы не должны напрямую обращаться к общему пути. Используйте свойство blackberry.io.sharedFolder, как показано в примере на этой странице: https://developer.blackberry.com/html5/apis/blackberry.io.html

Ваш путь файловой системы должен быть blackberry.io.sharedFolder + камера/IMG_00000037.jpg '

Безопасная конструкция песочнице BB10 означает, что каждое приложение имеет собственный путь к области общей файловой системы.

+0

Это сработало для меня. Ключ был в том, что путь нечетной файловой системы и не использовать 'resolveLocalFileSystemURI', поскольку URI не является локальным, а« общим ». Будем надеяться, что ребята Phonegap исправят это, чтобы 'camera.getPicture' вернул правильно отформатированный URL. –

0

доверия мне решить проблему с помощью этого источника:

<html> 
<head> 
<script type="text/javascript" src="local:///chrome/webworks.js"></script> 
<script type="text/javascript"> 

function log(e) { 
    console.log(e); 
} 

function takePicture(success) { 
    blackberry.invoke.card.invokeCamera('photo', function (path) { 
     success(path); 
    }, log, log); 
} 

function openFile (filePath, success) { 
    window.webkitRequestFileSystem(window.PERSISTENT, 1024*1024*1024, function (fs) { 
     fs.root.getFile(filePath, {}, function (entry) { 
      success(entry); 
     }, log); 
    }, log); 
} 

function uploadFile (entry, server, success) { 
    entry.file(function (file) { 
     var fd = new FormData(), 
      xhr; 
     fd.append("picture", file); 
     xhr = new XMLHttpRequest(); 
     xhr.open("POST", server); 
     xhr.onload = function (evt) { 
      if (xhr.status == 200) { 
       success(xhr.response); 
      } else { 
       log(xhr); 
      } 
     }; 
     xhr.ontimeout = log; 
     xhr.onerror = log; 
     xhr.send(fd); 
    }, log); 
} 

function start() { 
    takePicture(function (filePath) { 
     openFile(filePath, function (entry) { 
      uploadFile(entry, "http://cordova-filetransfer.jitsu.com/upload", function() { 
       alert("SUCCESS"); 
      }); 
     }); 
    }); 
} 

document.addEventListener('webworksready', function() { 
    blackberry.io.sandbox = false; 
    document.getElementById("startButton").disabled = ""; 
}); 

</script> 
</head> 
<body> 
<h1>Camera XHR Upload Sample</h1> 
<button id="startButton" disabled="disabled" onclick="start();">Start</button> 
</body> 
</html> 
0

основы chadtatro ответа от апреля 2'13:

Пожалуйста, добавьте в config.xml

<access uri="file:///accounts/1000/removable/sdcard/" subdomains="true"/> 

Я также добавил к моему проекту:

webworks plugin add com.blackberry.io 
0

У меня была такая же проблема, что и несколько дней. Получение изображений остановилось, и ничего в моем коде не было.

Остерегайтесь cordova-plugin-file, потому что в его версии 3.0.1-dev (возможно, другие тоже) приложение, которое вы разрабатываете, не запрашивает разрешения на доступ к файлам, и получение снимков с камеры или галереи не удастся.

Я решил его, используя версию 2.1.0 этого плагина:

cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-file.git#r2.1.0