You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "Kerri Shotts (JIRA)" <ji...@apache.org> on 2017/06/03 20:17:04 UTC

[jira] [Commented] (CB-12878) (browser) Problem using cordova.file.dataDirectory

    [ https://issues.apache.org/jira/browse/CB-12878?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16036080#comment-16036080 ] 

Kerri Shotts commented on CB-12878:
-----------------------------------

How are you testing in the browser? `cordova run browser` or something else?

> (browser) Problem using cordova.file.dataDirectory
> --------------------------------------------------
>
>                 Key: CB-12878
>                 URL: https://issues.apache.org/jira/browse/CB-12878
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: cordova-plugin-file
>    Affects Versions: 6.5.0
>            Reporter: Guilherme Dellagustin
>            Priority: Minor
>
> I'm using the file pluging togheter with the file transfer.
> cordova.file.dataDirectory contains 'filesystem:file:///persistent/' and this does not look to be correct.
> The download will fail here, but seems to be failing in the file plugin.
> {code:javascript}
> var fileTransfer = new FileTransfer();
> fileTransfer.download(
> 	encodeURI('source url'),
> 	targetUrl, // cordova.file.dataDirectory + 'file.txt'
> 	function(entry) {
> 		// success
> 	},
> 	function(error) {
> 		$log.log("Download error source " + error.source);
> 		$log.log("Download error target " + error.target);
> 		$log.log("Download error code" + error.code);
> 	},
> 	false
> );{code}
> I solved this by doing something like:
> {code:javascript}
> if($cordovaDevice.getPlatform() !== 'browser') {
> 	targetUrl = cordova.file.externalDataDirectory + 'media/' + filename;
> }
> else {
> 	// removed the media folder so that I do not have to create a directory, as it is not automatically created on the browser platform
> 	targetUrl = 'filesystem:'+ window.location.origin + '/persistent/' + filename;
> }
> {code}
> Remark: for some reson, this works for 127.0.0.1, but not for localhost.
> Plugins:
> cordova-plugin-admobpro 2.28.3 "AdMob Plugin Pro"
> cordova-plugin-browsertab 0.2.0 "cordova-plugin-browsertab"
> cordova-plugin-buildinfo 1.1.0 "BuildInfo"
> cordova-plugin-compat 1.1.0 "Compat"
> cordova-plugin-device 1.1.6 "Device"
> cordova-plugin-extension 1.5.1 "Cordova Plugin Extension"
> cordova-plugin-file 4.3.2 "File"
> cordova-plugin-file-transfer 1.6.2 "File Transfer"
> cordova-plugin-inappbrowser 1.7.0 "InAppBrowser"
> cordova-plugin-media 3.0.0 "Media"
> cordova-plugin-music-controls 1.4.1 "MusicControls"
> cordova-plugin-whitelist 1.3.2 "Whitelist"
> cordova-plugin-x-toast 2.6.0 "Toast"
> cordova-sqlite-storage 2.0.3 "Cordova sqlite storage plugin"
> cordova-universal-links-plugin 1.2.1 "Universal Links Plugin"



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org