fileUpload phonegap plugin does not work in iOS - javascript

I am using fileupload phonegap plugin to upload jpeg file to my server from iPad.
It is not working for me.
Here is my code:
window.plugins.fileUploader.uploadByUri('http://192.168.1.54:8080/POC/fileUploader', 'file://Documents/flower.jpg', null, 'myPhoto', 'flower.jpg', 'image/jpeg',
function(result) {
console.log('Done: ' + result);
},
function(result) {
console.log("Error: " + result);
}
);
In fileUploader.js file, I put an alert below the uploadbyuri method. But its not displaying. That means that method is not calling.
What mistake I have done?
Please help me.

Please check this plugins its works for me.
https://github.com/phonegap/phonegap-plugins/tree/master/iPhone/FileUploader
and if its not working please specify proper error that you are getting for upload image.

Me too had the same situation. FileUploader worked fine in cordova1.9.0. When i changed to cordova2.7.0 face the same situation. After a long time messing with the issue, I made it work by remnaming "Phonegap" to "cordova" in fileuploader.js file which is in www folder.
PhoneGap.addConstructor(function() {....
to
cordova.addConstructor(function() {....
and
return PhoneGap.exec('FileUploader.' + method, callback + '.success', callback + '.fail', callback + '.progress', server, file, fileKey, fileName, mimeType, params);
to
return cordova.exec(null,null,"FileUploader", "uploadByUri",[ callback + '.success', callback + '.fail', callback + '.progress', server, file, fileKey, fileName, mimeType, params]);

Related

Saving files in Phonegap

I've been running through docs and everything for the past couple of hours but with no success...
I want to download a file from some server and to save it on my phone (the directory where the app stores files that are only visible to my app and are deleted when the app is uninstalled). I would like to store a file and write to it (I've done the download part). With the following code, when I run it, it works and display the text from the "file" but when I search for the file using some file explorer apps, the file that I've "created" is nowhere near to be found.
Cheers!
EDIT Notes:
Okay so I've now even tried to create a file on my phone from the computer using a usb connection so I know for a fact the the file exists...
The path of the file where I created it from the pc is:
This PC\Galaxy S7 edge\Phone\Android\data\com.phonegap.musicapp2\text.txt
The response code that I get from JSON.stringify(dirEntry) is the following
{"isFile":false,"isDirectory":true,"name":"com.phonegap.musicapp2","fillPath":"/data/user/0/com.phonegap.musicapp2/", "filesystem":"","nativeURL":"file:///data/user/0/com.phonegap.musiapp2/"}
So when I run the code from bellow, it gives me
Error from getFile: {"code":1}
I've looked through the docs and it says that code 1 mean: NOT_FOUND_ERR (http://prntscr.com/n071kx)
"Code from bellow"
function readFile(fileEntry) {
fileEntry.file(function (file) {
var reader = new FileReader();
reader.onloadend = function() {
DebugConsole.log("Successful file read: " + this.result);
// displayFileData(fileEntry.fullPath + ": " + this.result);
};
reader.readAsText(file);
}, onErrorReadFile);
}
window.resolveLocalFileSystemURL(cordova.file.applicationStorageDirectory, function(dirEntry) {
DebugConsole.log(JSON.stringify(dirEntry));
dirEntry.getFile('text.txt', {create: false, exclusive: false}, function(fileEntry) {
//writeFile(fileEntry, null, isAppend);
readFile(fileEntry);
}, function(e) {
DebugConsole.log('Error from getFile: ' + JSON.stringify(e));
});
});
Sidenote:
App never asks for permission to access my internal storage.
I went into Apps/myapp/permissions and it showed that the app doesn't have permission to access the storage. I turned it on but still no luck.
I think I need to somehow request storage access from the app but I can't seem to find a way how?
I managed to find a solution with the following
window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory + "Android/data/app.name/files/", success, fail);

Kendo Editor - Function for thumbnailUrl is not working

I'm trying to use the image upload feature of kendo editor. Image uploading is working fine, but the thumbnails in the browse window is not showing correctly. For achieving this, I'm trying to call a function in thumbnail attribute. But, this is not firing. Please find the code snippet below and help me to find the issue.
transport: {
read: "api/imagebrowser/read",
thumbnailUrl: function (path, name) {
alert('inside thumbnail');
//return "api/imagebrowser/thumbnail?path=" + path + file;
},
uploadUrl: "api/imagebrowser/upload",
imageUrl: "Content/Images/{0}"
}
I'm using WEB API and angularjs. Any other suggestions to show the thumbnails are also welcome.
thumbnailUrl: function (path, name) {
path = "yourAPI/read" + "/" + name;
return path;
}
default path is "", and name is fileName.
I think you already solved...
Good luck.

Loading SVG (XML) with YUI3

I'm trying to load a SVG file with YUI3. I've read the page about the IO Utility - YUI Library and followed the example given there. I wrote
<script src="http://yui.yahooapis.com/3.18.1/build/yui/yui-min.js"></script>
<script type="text/javascript">
YUI().use("io", function(Y) {
Y.io('test.svg', {
on: {
success: function(id, o) {
console.log('success: ' + o.status + " ==> " + o.responseText);
},
failure: function(id, o) {
console.log('failure: ' + o.status + " ==> " + o.statusText);
}
}
});
});
</script>
The real strange thing is, that on running the script I get a "failure: 0 ==>", thus o.status is 0, which is not a HTTP status code and there is no o.statusText, although the failure event is triggered.
Here you can download the two files in a zip file.
What I'am doing wrong?
Thanks for your help!
Are you viewing the html directly in the browser? In order for Ajax to function the file needs to be on a webserver. If you are using a mac, spin up a single line webserver in the directory you are in like this:
python -m SimpleHTTPServer
Once I had your code running under a webserver it loaded the SVG properly.

node-webkit windows file system seperator?

Im currently working on a simple file-explorer with NW.js
Im developing on a linux-machine and there it works fine until now, but i tested it on a windows-system at work and there is a problem with listing all files in a directory. I developed it to work on both systems (i thought) here´s a link to my repo please note the file: js/main.js where i set the seperator-variable to be "\" on windows platforms (in function: getRootDir()).
In JS this:
alert("\\");
gives me: "\"
isnt that the seperator for windows?
Any help would be appreciated.
I was playing around a bit and found out that the async one works and the sync one doesnt - here the async one:
fs.lstat(rootElement.path + seperator + file, function(err, stats) {
if (err) {throw err;}
if (stats.isDirectory()) {
createFolderView(rootElement, file);
} else {
createFileView(rootElement, file);
}
});
and here the sync one:
if (fs.lstatSync(rootElement.path + seperator + file).isDirectory()) {
createFolderView(rootElement, file);
} else {
createFileView(rootElement, file);
}
but shouldnt work both the same way - or am i missing something?

Cannot find file in the gallerie after downloading it with PhoneGap in Android

i have a problem with the the downloaded files in my PhoneGap-App for Android.
The download-Function from PhoneGap actually works quite well i think. It gets the file from the URL and
stores it on the SD-Card. (Code is below)
So where is the Problem? When I download a JPG or PNG to the
Download-folder, i want it be accessible through the native Gallery.
But the picture don´t appear in the gallerie. To see it I have to
restart the phone or I have to use another App like Astro.
Is there a "Refresh_the_native_Gallerie"-Function or something like that?
Thank you very much.
try {
var filePath = 'file:///mnt/sdcard/Download/google.png'; // Correct filePath
var url = "https://www.google.de/images/srpr/logo3w.png"; //Correct URL
var fileTransfer = new FileTransfer();
fileTransfer.download(url, filePath, function(entry) {
console.log("s3_download download complete: " + entry.
// Do i need a "Refresh_all_other_Apps"-function here?
}, function(error) {
// Normally no Error
console.log("s3_download download error source " + error.source);
console.log("s3_download download error target " + error.target);
console.log("s3_download download error code" + error.code);
});
} catch (e) {
console.log("downloadTest ERROR: " + e);
}
Cannot answer my own question so fast only edit my question. So here is the answer:
I wrote a little PhoneGap-Plugin, which does actually nothing more than calling the code from zapl. Thanks again. Hope it will help someone with the same problem.
You can find the code here: https://github.com/philipp-at-greenqloud/pluginRefreshMedia
I don't know if that helps you in PhoneGap / JavaScript context:
Your problem is that the gallery will only display files that are indexed in the device media-database. Just adding a file to the file system will not automatically add it to that database. And pretty much the only time a rescan / update of that database happens is when you reboot the device or remount the sdcard (after it was shared with a PC or in case you ejected it and put it back in).
To have a file added to the database the simplest way to to that is to send Intent#ACTION_MEDIA_SCANNER_SCAN_FILE to the MediaScanner to let it add your file to the database. Once that is done the file will show up in the gallery.
Java code for that would be
File newImage = new File("/mnt/sdcard/Download/google.png");
Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
scanIntent.setData(Uri.fromFile(newImage));
sendBroadcast(scanIntent);
I wrote a little PhoneGap-Plugin, which does actually nothing more than calling the code from zapl. Thanks again.
Hope it will help someone with the same problem.
You can find the code here: https://github.com/philipp-at-greenqloud/pluginRefreshMedia
This is a well needed plugin. I have been trying to do work arounds for this issue and the plugin works a treat. I was looking at developing one myself, but you have done a great job. My headaches are now subsiding. This works for me.

Categories

Resources