I have the following code to create a file from a Firefox Add-on SDK extension.
panel.port.on("mbData", function(data) {
console.log("Recebi dados. Data: " + data);
OS.File.writeAtomic("mb.txt", data, {write: true, create: true}).then(function(aResult) {
console.log("Criei o ficheiro\n");
}, function(ex) {
console.log("Error!\n"+ex);
});
});
The code above works great when I run using jpm run. But, when I create the xpi file (jpm xpi) and install it on Firefox it doesn't work. It seems that the file it's not being created. In addition, I can't access any log files.
Am I doing anything wrong here?
try to use this line:
Components.utils.import('resource://gre/modules/osfile.jsm');
Before to call the writeAthomic method.
Related
i am trying to post an image to a a backend server that is an Express Server.
I am using cordova file transfer(installed through cordova plugin add cordova-plugin-file-transfer )
I have imported the file transfer like this:
import {Transfer} from 'ionic-native';
here is my component that posts the file to the server
save() {
base64Image = open("/Users/user1/1.jpg");
let ft = new Transfer();
let filename = "example" + ".jpg";
let options = {
fileKey: 'file',
fileName: filename,
mimeType: 'image/jpeg',
chunkedMode: false,
headers: {
'Content-Type' : undefined
},
params: {
fileName: filename
}
};
ft.upload(base64Image, "http://localhost:3500/api/v1/file", options, false);
}
the error i get whenever i call the save function is:
FileTransfer is not defined
help will be appreciated
Install with ionic since you are using ionic-native.
ionic plugin add cordova-plugin-file-transfer --save.
The save option is to ensure there is an entry in config.xml.
Also call any plugin within
platform.ready().then(()=>{})
Plugins are loaded after the app is loaded.
UPDATE:
Cordova is not supported and most plugins will not load with ionic serve command.
You need to run it in an emulator or a device.
I'm attempting to write an automated installer for a *.exe file. I am using node-webkit, my unzipper is decompress-zip. I am downloading the installer via AJAX:
$.ajax({
type: "GET",
url: 'https://mywebste.com/SyncCtrl.zip',
contentType: "application/zip;",
success: function (dat) {
console.log(dat)
fs.writeFile("./SyncCtrl.zip", dat, function () {
console.log(dat)
})
},
error: function (err) {
console.log(err)
fs.writeFile("./SyncCtrl.zip", err.responseText, function () {
})
}
})
The .zip is written through the err.responseText content. I know this isn't best practice, but I haven't been able to get it into the success callback, even though the response code is 200. This is for another question though.
After I write the .zip file to disk, I wait for an authentication request, then unzip it in the success callback:
var unzip = new dc("./SyncCtrl.zip")
unzip.on('error', function (err) {
console.log("Something went terribly wrong.")
console.log(err)
})
unzip.on('extract', function (log) {
console.log("Finished!")
console.log(log)
})
unzip.on('progress', function (i, c) { //index, count (irrelevant for single file)
console.log("Extraction progress.")
})
unzip.extract({
path: "./SyncCtrl"
})
This is nearly copy/pasted directly from the decompress-zip github page. This fails, in the error handler it prints:
Error {message: "File entry unexpectedly large: 80606 (max: 4096)"}
I assume this limit is in MB? This is very confusing as in both locations the file size on disk is 1.7MB for the file I'm trying to extract. Any help is greatly appreciated.
The best way to accomplish this is to interpret the static file as a stream.
Simply using the static file on the server, this is my working node-webkit code:
var file = fs.createWriteStream("./MOCSyncCtrl.zip");
var request = https.get("https://moc.maps-adr.com/MOCSyncCtrl.zip", function (response) {
response.pipe(file);
});
I get this error every time i compile my PhoneGap 2.9.0 project. I copied "www" folder into my Microsoft Visual Studio 2010 Codrova Project because iw anted to test the program on WP 7(I've already tested it on Android and iOS emulators and devices).
Error:["Unable to get value of the property 'content': object is null or undefined file:x-wmapp1:\/app\/www\/index.html Line:1","DebugConsole380383071"]
As far as i've found out, this bug is fixed only if i delete cordova.js include in my index.html file. I'm hoping that fixing this bag will solve the problem of file downloading in my program, because it's not working in WP 7 now. Here is the function for file downloading:
function fileDownload(fileName, finalName) {
window.requestFileSystem(
LocalFileSystem.PERSISTENT, 0,
function onFileSystemSuccess(fileSystem) {
fileSystem.root.getFile(
"dummy.html", {create: true, exclusive: false},
function gotFileEntry(fileEntry){
var sPath = fileEntry.fullPath.replace("dummy.html","") + "Appname/Cachefolded";
var fileTransfer = new FileTransfer();
fileEntry.remove();
fileTransfer.download(
finalName,
sPath + finalName,
function(theFile) {},
function(error) {}
);
},
null);
},
null
);
};
In addition, i'm using few PhoneGap API's:
* Device
* Connection
* FileSystem
* LocalStorage
Data is downloaded via Ajax like this:
$.ajax({
url: base + "user.php?imei=" + imei,
type: 'POST',
dataType:"json",
cache: false,
success: function(data) {
fileDownload(data.img, "avatar.jpg");
}
});
I'll publish all nessesary code if you are interested in a specific part. Don't wanna post it here to keep my question readable. Thanks for any help in advance.
P.S. Line 1 of the code is:
<!DOCTYPE html>
Using php with the laravel framework. I have a delete request to delete a file entry on my website, it's working fine locally but on my webserver it's failing.
// Ajax call
$.ajax({
url: BASE+'/contests/any/entries/any',
type: 'DELETE',
data: {
entry_id : entry_id
},
success: function() {
$(".entry-item#"+entry_id).remove();
}
});
My route:
Route::delete('contests/(:any)/entries/(:any)', 'entry#destroy');
Controller method:
public function delete_destroy() {
$entry = Entry::find(Input::get('entry_id'));
Entry::find($entry->id)->delete();
File::delete(URL::base() . 'public/uploads/' . $entry->filename);
}
When I check ajax requests viewing the network tab in chrome developer tools I get a status 404 not found on this delete method while it's working fine locally in wamp. Can anyone tell me what is wrong here and what this 404 not found exactly means?
What exactly isn't found here?
Actually, 404 not found means that your file doesn't exist and it could be also because of a wrong path and I think it could be because you are using
File::delete(URL::base() . 'public/uploads/' . $entry->filename);
which returns most probably something like
http://yourdomainpublic/uploads/filename
Instead, you can use
File::delete(path('public').'uploads/' . $entry->filename);
Which will output something like this
http://yourdomain/public/uploads/filename
I am trying to run an xhrGet like this one:
dojo.provide("test");
dojo.declare("test",null,{
getVersion: function(){
details =
{
url: "../version.txt",
content: "test",
handleAs: "text",
timeout: 4000,
load: function(data)
{
console.log("result" + data);
},
error: function(error)
{
console.log("Error" + error);
}
}
var dfd = dojo.xhrGet(details);
return dfd;
});
and I am getting this error:
Error: Deferred Cancelled: [Exception... "Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsIXMLHttpRequest.send]" nsresult: "0x80520012 (NS_ERROR_FILE_NOT_FOUND)" location: "JS frame :: file:///C:/Dojo1.4.3/dojo/_base/_loader/bootstrap.js :: anonymous :: line 1351" data: no]
file:///C:/Dojo1.4.3/dojo/_base/_loader/bootstrap.js
Line 0
The file I am trying to retrieve is relative to dojo, therefore is located under Dojo1.4.3/version.txt
Other note.... I am not running it on a server, I am simply loading the html file with reference to the dojo class I have created.
thank you all for your time
EDIT
SOLUTION
I found the solution
https://developer.mozilla.org/en/Same-origin_policy_for_file%3a_URIs
you need to enable this policy in Firefox
You cannot do AJAX requests if your page is being served directly via file://, for security reasons or something like that. You will need to set up a HTTP server and serve your page via that.
Also, is there any particular reason why you are using an old version of Dojo here? The current version is 1.7