Phonegap File Transfer Errors

I am trying to get the PhoneGap application to create a directory on a mobile device, but I continue to work with the same errors that are a mixture:

ENCODING_ERR - 5 - The URL is invalid. Make sure the URL is complete and valid.

PATH_EXISTS_ERR - 12 - A file or directory with the same path already exists.

INVALID_MODIFICATION_ERR - 9 - The requested modification is not allowed. For example, an application may try to move the directory to its own child or move the file to the parent directory without changing its name.

$( document ).on( 'click', '#A2', function () { downloadPhoto(); } ); function downloadPhoto() { alert( "Downloading" ); window.requestFileSystem( LocalFileSystem.PERSISTENT, 0, function systemSuccess( dirEntry ) { alert( "Download about to begin" ); dirEntry.root.getDirectory( 'thisfilenamewillneverexist', { create: true }, function ( fileSystem ) { alert( fileSystem ); }, errorHandler ); }, errorHandler ); } function errorHandler( e ) { var msg = ''; switch ( e.code ) { case FileError.ENCODING_ERR: msg = 'ENCODING_ERR'; break; case FileError.INVALID_MODIFICATION_ERR: msg = 'INVALID_MODIFICATION_ERR'; break; case FileError.INVALID_STATE_ERR: msg = 'INVALID_STATE_ERR'; break; case FileError.NO_MODIFICATION_ALLOWED_ERR: msg = 'NO_MODIFICATION_ALLOWED_ERR'; break; case FileError.NOT_FOUND_ERR: msg = 'NOT_FOUND_ERR'; break; case FileError.NOT_READABLE_ERR: msg = 'NOT_READABLE_ERR'; break; case FileError.PATH_EXISTS_ERR: msg = 'PATH_EXISTS_ERR'; break; case FileError.QUOTA_EXCEEDED_ERR: msg = 'QUOTA_EXCEEDED_ERR'; break; case FileError.SECURITY_ERR: msg = 'SECURITY_ERR'; break; case FileError.TYPE_MISMATCH_ERR: msg = 'TYPE_MISMATCH_ERR'; break; default: msg = 'Unknown Error'; break; }; alert( 'Error: ' + msg ); } 

Why or how does this file name already exist if it is the first time I create it?

+4
source share
2 answers

It was possible to fix the error, it turns out you do not need to include "root" when creating the file in the newly created directory.

Code for someone else stuck in this problem or something similar:

 var folderDir; var fileDir; var FolderName = "OSMaps"; $( document ).on( 'click', '#A2', function () { window.requestFileSystem( LocalFileSystem.PERSISTENT, 0, downloadPhoto, errorHandler); } ); function downloadPhoto(fileSystem) { fileSystem.root.getDirectory( FolderName, { create: true, exclusive: false }, function ( dirEntry ) { folderDir = dirEntry; -> folderDir.getFile( 'test.jpg', { create: true, exclusive: false }, <- function ( fileEntry ) { fileDir = fileEntry; }, errorHandler ); }, errorHandler ); 
+5
source

As a result of a successful requestFileSystem request, you will be passed the fileSystem parameter, which in simple language is the mother (main object / parent element) of the API files.

If you execute " System.root.getDirectory " in the successallallback file, you will be given the " directoryEntry " parameter, which basically matches the " fileSystem.root " parameter , so you can use all the methods listed in the directoryEntry section without problems and not use root

+1
source

Source: https://habr.com/ru/post/1500510/


All Articles