phonegap file transfer with space in the file name - android

I'm using Cordova 1.9.0 for an Android App. The same code, on IOS works fine.
On Android, i find a problem for the file trasfert from remote location to local.
The problem is on the file name: someone has space. I try to do
.replace(" ","%20")
but doesn't work. It gives me the following error
07-03 12:06:32.503: E/FileTransfer(337): java.io.FileNotFoundException: http://www.mydomain.com/sa02 -.jpg

There was a bug in FileTransfer upload which a fix was checked in for 1.9.0.
https://issues.apache.org/jira/browse/CB-978

url = url.replace(/ /g,"%20");

PhoneGap 1.9.0 and 2.0.0 break fileTransfer.download() for names with spaces.
The workaround for now until PhoneGap 2.1.0 comes out is
var source = encodeURI(file path here);
source = source.replace(/%/g,"%25");

Related

Unity, JSON file - Android problem, can't find my JSON file

I wrote a script that allows you to read and write to a json file. As long as I tried the script in unity editor, I didn't have any problems. But when I switched to installing the application on an Android device, I can't find my json file.
The json file is called "playerData.json" and has been placed in a folder called "playerData.json".
This is the code for the path of the json file (working on unity but not working on android)
path = Application.streamingAssetsPath + "/playerData.json";
I tried using this string of code to get the code to work on android as well, but there is no way to get it to work.
path = System.IO.Path.Combine(Application.streamingAssetsPath, "/playerData.json");
I only wrote the line concerning the path as my android device cannot find the JSON file. Thanks everyone for the help!
Application.streamingAssetsPath does not work on Android and WebGL
It is not possible to access the StreamingAssets folder on WebGL and Android platforms. No file access is available on WebGL. Android uses a compressed .apk file. These platforms return a URL. Use the UnityWebRequest class to access the Assets.
There is a workaround though as mentioned using UnityWebRequest, can find an example in this Unity Answer

window.resolveLocalFilesystemUrl in ionic 2

I need to save a downloaded file in my ionic 2 path and use that ineteral url path.
for downloading: using file-transfer plugin.
const fileTransfer = new Transfer();
fileTransfer.download(trackObj.remoteUrl,cordova.file.dataDirectory+"audio/"+filename).then((entry)=>{
console.log("download completed:"+entry.toURL());
});
entry.toURL() is giving path like file://...... in need to use that path to play using Media plugin. But, Media plugin is not accepting path with file://...,
this.playerStatic = new MediaPlugin(internalFilePath,onStatusPlayerUpdate);
so, on googling foundout: https://forum.ionicframework.com/t/ios-9-cant-play-audio-video-files-that-are-downloaded-to-device/37580/4
so using "cdvfile://localhost/library-nosync/" + fileSrc; as a temporary solution. Its not working for android.
so to be able to use in both platforms, i should be able to follow other solution, where the path will be resolved to InternalURL. when i try
window.resolveLocalFileSystemURL(src, function(dir){});
its saying resolveLocalFileSystemURL is not a function.
anybody can help me with it? how to use window.resolveLocalFileSystemURL in ionic 2?
I am using it in ionic 3, for iOS build. Please check the code:
this.file.resolveLocalFilesystemUrl(this.file.dataDirectory).then((entry) => {
console.log("Success! Got a DirectoryEntry",entry);
});
Here, I am using cordova-plugin-file but I think it should work for cordova-plugin-file-transfer also. Please try and let me know, if there is any issue.

Ionic Cordova FileUpload error: Not allowed to load local resource

I am new to Ionic and I am trying to upload an image taken from camera that is stored in Android filesystem:
var ft = new FileTransfer();
console.log('Uploading: ' + fileURL);
ft.upload(fileURL,
encodeURI("http://192.168.192.62:3000/api/meals/picture"),
pictureUploaded,
function(error) {
console.err(error);
$ionicLoading.show({template: 'Ooops error uploading picture...'});
setTimeout(function(){$ionicLoading.hide();}, 3000);
},
options);
var pictureUploaded = function() {
console.log('uploaded!');
$ionicLoading.hide();
};
fileUrl is pointing to an existent image: file:///data/data/com.ionicframework.nutrilifemobile664547/files/Q2AtO1462636767466.jpg
In chrome://inspect/#devices console I get the following error and it looks like because of the error the FileOptions are also not properly sent, this is the error (Not allowed to load local resource):
Cordova version: 6.1.1
Ionic version: 1.7.14
This happens when you use the "livereload" option with Ionic.
Try running in normal mode
With ionic webview >3.x, you have to use convertFileSrc() method.
For example if you have a myURL local variable such as file:// or /storage.
let win: any = window; // hack ionic/angular compilator
var myURL = win.Ionic.WebView.convertFileSrc(myURL);
Another possible reason is that you have a webview plugin installed (like https://github.com/ionic-team/cordova-plugin-ionic-webview or just https://github.com/apache/cordova-plugin-wkwebview-engine). Also this will not allow to use cdvfile:// protocol as well.
It might be too late but... you could convert native path to blob using File then convert blob to URL using URL.createObjectURL(blob) and passing/setting as src to your html element. This is unnecessary for production environment but you could use it for development with -lc. It might work
07-Dec-2018
This is the version where it works for me on Ionic 3.9.2 app.
Remove the latest version of webview and then:
i.e. ionic cordova plugin add cordova-plugin-ionic-webview#1.2.1
https://github.com/ionic-team/cordova-plugin-ionic-webview/releases/tag/v1.2.1
Note: This version works fine with normalizeURL() method.

Error when attaching files with PhoneGap EMailComposer plugin

I'm using Phonegap EMailComposer plugin with Android to send a file attached but when the mail client (gmail app) opens I always get the same error "the file can't be attached'.
This is the code I'm using:
cordova.plugins.email.open({
to: 'XX',
subject: 'XX',
body: 'XX',
attachments: '//file.csv'
});
I'm quite sure the path is right becasuse when I use any other file path the error changes into "attached file can't be empty'.
I'm using cordova CLI 4.0.0 and plugin version is 0.8.2. I've tested it in Android 4.4.2 and 4.2.1
Any idea?
According to the documentation you need to use
attachments: 'file:///storage/sdcard/icon.png', //=> Android
but that didn't work for me so I tried without storage and it works for me. (I'm using Android 5.1.1 for my tests, so i don't know if it works in your case for Android 4.x)
Try with:
attachments: 'file:///sdcard/file.csv

Android: Phonegap 3.1.x fail to load geolocation plugin

We are using Phonegap 3.1.0-0.15.0 and the application chocked when trying to access location information.
Works fine in iOS however the App chock on Android
We are using:
navigator.geolocation.getCurrentPosition(app.location.onSuccess, app.location.onError);
and we also tried:
var geo = cordova.require('cordova/plugin/geolocation');
geo.getCurrentPosition(app.location.onSuccess, app.location.onError);
The logcat mentioned the following:
Could not find cordova.js script tag. Plugin loading may fail. at file:///android_asset/www/phonegap.js:1511
Uncaught module cordova/plugin/geolocation not found at file:///android_asset/www/phonegap.js:56
The plugin was added using:
cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git
Are we doing something wrong ?
Thank you in advance
/Edwardo.
Just to answer my own questions. I removed all the plugins manually and then add them (including the problematic geolocation plugin) using the following command:
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git
That solved my issue.
Edward.

Categories

Resources