PhoneGap FileTransfer download stops after 6 kilobyte - download

Hi Stackoverflowianers!
It's me again, having a PhoneGap question:
Working on PhoneGap 2.8.1 I made a file download working by the fileTransfer.download() method. Seams to work like a charm but all files (no metter what size or extension) are downloaded to 6 kilobyte files. Source and target is ok as far as I can see but the download ends regularly after 6 kilobytes. No error, no nothing...
My code:
navigator.notification.activityStart("Please wait....", "Loading");
var fileTransfer = new FileTransfer();
var uri = $(this).attr('file');
var fName = uri.substring(uri.lastIndexOf('/')+1);
var localPath = '/mnt/sdcard/download/';
var filePath = localPath+fName;
fileTransfer.download(
uri,
filePath,
function(entry) {
navigator.notification.activityStop();
navigator.notification.alert('/sdcard/download/', function(){}, 'Saved in...', 'Close');
console.log("download complete: " + entry.fullPath);
},
function(error) {
navigator.notification.alert('Code: '+error.code, function(){}, 'Error...', 'Close');
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
}
);
Have anybody had this problem before? Does anybody have a glue what could be the reason for this misbehaviour???
I'd be very happy for some - or at least one - hint to the right direction...!
Thnx. in advance for your reply.
Ingmar

Sorry to all Stackoverflowianers!!! I solved it my self...
But enyway, if you ever run into this just get the idea here to help your self:
"Just copy the downloaded 6 kilobyt (or more or less) file from your device to the PC and - e.g. with Notepad++ - have a look what is in there. The content of the file will help you directly to solve your problem..."
Greatinx,
Ingmar

Related

Error retrieving image from URL with SpreadsheetApp.newCellImage() builder

My application is trying to insert images to google drive sheet using google app script.
It works fine...
but it hang up intermittently with the response error from google script:
Exception: Error retrieving image from URL or bad URL:
https://drive.google.com/uc?id=1uvjg9_ZZg2sI5RYbPMEn6xXJhhnwuFyq&export=download.
The code is :
var fpm_mon_image = file_from_folder(id_folder_images , image_AR ) ; // get "image_AR" from folder
var url_mon_image = fpm_mon_image.getDownloadUrl() ;
var image = SpreadsheetApp.newCellImage().setSourceUrl(url_mon_image).setAltTextTitle(titre).toBuilder().build() ;
Utilities.sleep(1000); // for testing ...
SpreadsheetApp.flush();
Utilities.sleep(1000);
var rangeIma= fpm_sp.getRange(scal_li_SP +1, 2) ;
rangeIma.setValue(image).setVerticalAlignment('bottom') ; // stop here with error above
It works fine 5, 10 times then it hang up 2, 3, 5 times and then works fine again.... (I start loosing my hairs ;-))
I tried :
var srcfile = DriveApp.getFileById(id_mon_image);
srcfile.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW);
var image = fpm_sp.insertImage(srcfile.getBlob(), my_col , my_row);
but the image in not inserted in a cell...
Could you help please ?
Many thanks.
Unfortunately, I cannot replicate your situation of Exception: Error retrieving image from URL or bad URL:. So, although I'm not sure about your actual situation, how about the following modification?
Modified script:
Before you use this script, please enable Drive API at Advanced Google services.
var fileId = "###"; // Please set the file ID of your image.
var url = Drive.Files.get(fileId).thumbnailLink.replace(/\=s.+/, "=s512");
var title = "sample title";
var image = SpreadsheetApp.newCellImage().setSourceUrl(url).setAltTextTitle(title).build();
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange("A1").setValue(image);
When this script is run, a thumbnail link is retrieved from the image file using Drive API. And, the image size of the image is changed. And, the image is put to the cell "A1" of the active sheet.
In this case, if the issue of image size occurs, this issue can be removed. And, if the issue of sharing the file occurs, this issue can be also removed. By this, I thought that your issue might be able to be removed.

File access permission in Swift on OSX

I'm using:
let dialog = NSOpenPanel()
to get a file URL.
I'm then reading in the contents of the text file with:
let content = try String( contentsOf: dialog.url)
This works!
I'm then trying to read in another text file in the same directory with a different extension:
let b = dialog.url?.deletingPathExtension()
// Add the new file extension
let c = b?.appendingPathExtension("TSN")
let content2 = try String( contentsOf: c)
With this I get:
"The file “FLO5.TSN” couldn’t be opened because you don’t have permission to view it."
If I try and open the .tsn file with a URL from a NSOpenPanel() dialog result it works. I need to open several data files from this same directory with different extensions. Is there a way to do this?
set off sandbox!!)
Xcode 9 and later enables sandboxing by default, which severely limits interactions with the system.
Select your target, then Capabilities and set Downloads Folder to Read/Write:
In my case, solve it's startAccessingSecurityScopedResource
Example:
let selectedFile = try result.get() // get path to file
do {
// get access to open file
if selectedFile.startAccessingSecurityScopedResource() {
let path = selectedFile.path
let data = NSData(contentsOfFile: path)
print(data) // array bytes
selectedFile.stopAccessingSecurityScopedResource()
}
} catch {
// Couldn't read the file.
print(error.localizedDescription)
}
Apple wiki about this feature https://developer.apple.com/documentation/foundation/nsurl/1417051-startaccessingsecurityscopedreso

Why is the Firefox webkitdirectory implementation so slow reading from DVD/CD?

Im working on a file upload service using HTML5. In the use case the user wants to upload whole directory, which he receives in form of a CD/DVD.
Reading directories is possible in Chrome using the
webkitdirectory | mozwebkitdirectory | directory
attribute.
Mozilla Firefox has adapted this feature this August, in Version 55.
Reading from Hardisk, this feature works great on Chrome, and still alright, even though a little slower, on Firefox.
But as soon as the user picks a CD/DVD path, or a directory which is located on the CD/DVD, Firefox becomes very slow and hangs more often than not.
Here is a simple snippet, which loads a directory, iterates over the file meta data, and loads one file into memory to show its size.
document.getElementById("filepicker").addEventListener("change", function(event) {
let output = document.getElementById("listing");
let files = event.target.files;
let fileReader = new FileReader();
let start = new Date().getTime();
for (let i=0; i<files.length; i++) {
let item = document.createElement("li");
item.innerHTML = files[i].webkitRelativePath;
output.appendChild(item);
};
console.log("Time used for iterating over file meta: " + (new Date().getTime() - start) / 1000 + "s");
fileReader.addEventListener("load", function(evt) {
console.log("File Loaded");
console.log("Time for loading Single File into memory: " + (new Date().getTime() - start) / 1000 + "s");
let blob = new Blob([new Uint8Array(evt.target.result)], {type: "arraybuffer"});
console.log("Blob Size is: " + blob.size); //To show that file is read to memory.
}, false);
console.log("START LOADING FILE");
start = new Date().getTime();
fileReader.readAsArrayBuffer(files[0]);
}, false);
<div>
Select Directory:
<input id=filepicker type="file" webkitdirectory mozdirectory msdirectory directory multiple>
<div>
<div id=listing></div>
You can try for yourself, maybe the error depends just on my CD/DVD drive.
The questions I have are:
Do you have similar problems loading from CD/DVD drive?
Is this a known error in the Firefox webkitdirectory implementation?
Am I doing something wrong, is there another way to get Filenames and load files into memory ?
If you have similar problems I might fill an Issue report to Mozilla.

PhoneGap/Cordova V3.4.0 - GPS Plugin Not Working Properly- Cache the latest point forever

I tried and struggled for several days to get the Cordova V3.4, GPS Plugin to work properly.
I see on the internet and also here for a lot of solution and suggestion, but non of them solved this issue.
The issue is occur only on Phone Gap Apps[with APK Deploy on Device or in Simulator] (In browser the GPS work fine).
Testing Details:
Phone: Nexus 5 And Samsung Galaxi 2.
Simulator: Android Regular Simulator And GenyMotion Simulator.
Cordova Installation: By CLI
I added geolocation plugin by CLI
I added Permission to AndroiedManifest:
uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"
uses-permission android:name="android.permission.INTERNET"
uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"
uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
in config.xml:
plugin name="Geolocation" value="org.apache.cordova.GeoBroker"
ISSUE:
After Clean Reboot:(Without GPS)
I enter my app and I an get error with error code - As expected :)
I Enable the GPS, re Enter my App, and see the location of my place - As Expected
I Disable the GPS, re Enter my App, and see other location of my place - As Expected
GPS Disable, re enter to my App, and see the SAME POINT AS BEFORE(I dont know how but it cache it - I disable the maximumAge option by put it with value 0)
GPS Disable, Wireless Disable, 3G Network Disable, I run my App and I get the latest location Same As Point 4. And Now the same issue happens forever and i will get the same position till i will turn on my GPS OR I will reboot my device.
P.S: BTW I tried also to work just with HTML5 Geo Location and I get the SAME ISSUE.
My code: (I tried several times but this is the latest that I've tried to use. I try two call to getCurrentPosition because I read that sometimes one call is Not enough :():
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function success(pos) {
var crd = pos.coords;
var str = 'Your current position is:'+'Latitude : ' + crd.latitude+'Longitude: ' + crd.longitude+'More or less ' + crd.accuracy + ' meters.' + ' TimeStap : ' + crd.ti;
alert(str);
}
function error1(err) {
alert('error 1');
alert('ERROR(' + err.code + '): ' + err.message);
var options = {
enableHighAccuracy: false,
timeout: 5000,
maximumAge: 0
};
navigator.geolocation.getCurrentPosition(success, error2, options);
}
function error2(err){
alert('error 2');
alert('ERROR(' + err.code + '): ' + err.message);
}
navigator.geolocation.getCurrentPosition(success, error1, options);
},

Photoshop javascript save error 8800

In my javascript, in Windows 7, Photoshop CS2 & Photoshop CS5, it throws an error:
Error 8800: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.
- Could not save a copy as "C:...\wcb-010B-11Y.jpg" because the file could not be found.
Line: 458
-> docRef.saveAs( saveFile, jpgSaveOptions, true, Extension.LOWERCASE );
here is a summary of the code to save the image:
var selectedSaveDir = "~/Desktop/";
var sFileNamePreFix = "wcb-";
var docRef = app.activeDocument;
var docName = app.activeDocument.name;
var docNewName = docName.substr( 0, docName.length - 4 ); // strip file extension
var sNewDocName = sFileNamePreFix + docNewName + ".jpg"
var sNewFileName = selectedSaveDir + sNewDocName;
//alert( "sNewFileName = " + sNewFileName ); // test to verify correct location
var saveFile = new File(sNewFileName);
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.quality = 12;
docRef.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);
In Windows XP, this script works very well in CS2 with no problems.... just in Windows 7 is where this issue occurs using CS2 or CS5.
The problem seems to be similar to : Photoshop Javascript scripting saving and closing document
But I don't know his OS.
I've added the "alert(" and confirmed the save folder & name is correct and can be saved to, but same issue.
Could it be a UAC issue in Windows 7 ? and how do you Fix it ? I've turned off all UAC settings (I think I did it correctly), but it still occurs.
Any Help ?
You missed out " var docRef = app.activeDocument;" (which i've added); but apart from that, in CS2 the script saves out a jpeg to the desktop (wcb-text test.jpg). It's obvious, but have you made sure the image is flattened or doesn't contain any information that cannot be stored in a jpeg - like paths for example.
Try forcing a flatten before saving
//flatten the image
docRef.flatten();
Another thing to try is to save out the file to another directory. I know that long file names (especially with spaces in) can cause problems - I think there's a limit to 300 characters in the file path.
I just found that, in new versions of PS this particular path variable gives the error 8800:
var selectedSaveDir = "~/Desktop/";
Use full path instead and use apostrophes instead of quotes:
var selectedSaveDir = 'C:/Users/yourname/Desktop/';

Resources