Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Highlighted
New Contributor
Posts: 9
Registered: ‎03-13-2014
My Device: N/A
My Carrier: N/A

Re: Cordova 3.4 / File plugin 1.0.1 - resolveLocalFileSystemURL for camera image

Hi Bryan,


I lied when I said that was my last question.  I can't seem to move or copy camera images to persistent storage.  I always get an error code 1 (not found) when trying.  Here is a full example.

 

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
        <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" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <title>Hello World</title>
    </head>
    <body>
        <div class="app">
            <button id="btnTakePic" onclick="takePic()">Take Pic</button>
        </div>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript">

			var fileErrors = {};
		
			function onDeviceReady() {

				fileErrors[FileError.NOT_FOUND_ERR] = 'Not found';
				fileErrors[FileError.SECURITY_ERR] = 'Security';
				fileErrors[FileError.ABORT_ERR] = 'Abort';
				fileErrors[FileError.NOT_READABLE_ERR] = 'Not readable';
				fileErrors[FileError.ENCODING_ERR] = 'Encoding';
				fileErrors[FileError.NO_MODIFICATION_ALLOWED_ERR] = 'No modification allowed';
				fileErrors[FileError.INVALID_STATE_ERR] = 'Invalid state';
				fileErrors[FileError.SYNTAX_ERR] = 'Syntax error';
				fileErrors[FileError.INVALID_MODIFICATION_ERR] = 'Invalid modification';
				fileErrors[FileError.QUOTA_EXCEEDED_ERR] = 'Quota exceeded';
				fileErrors[FileError.TYPE_MISMATCH_ERR] = 'Type mismatch';
				fileErrors[FileError.PATH_EXISTS_ERR] = 'Path exists';
			
				if (cordova.platformId === "blackberry10") {
					window.resolveLocalFileSystemURL = window.resolveLocalFileSystemURI;
					
					if (!window.requestAnimationFrame) {
						window.requestAnimationFrame = window.webkitRequestAnimationFrame;
					}
				}		
			}
			
			function takePic() {
			
				navigator.camera.getPicture(function (url) {
						
					window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSys) {
					
						window.resolveLocalFileSystemURL(url, function(entry) {
					
							var d = new Date();
							var n = d.getTime();
							var e = ".jpg";
							var fileName = n + e;
							
							fileSys.root.getDirectory('hello_world', {create: true}, function(dir) {
							
								entry.moveTo(dir, fileName, function(movedEntry) {
									alert('file moved');
								}, function(error) { 
									alert('moveTo fail (' + error.code + '): ' + fileErrors[error.code]);
								});
							
							});
					
						});
					
					});
						
				});
			
			}
			
			document.addEventListener('deviceready', onDeviceReady, false);
			
        </script>
    </body>
</html>