security error on getFile call on given directory entry in chrome app - google-chrome-app

Summary : I am downloading files to chrome app sandbox file system. I have directory called 'downloads' in chrome app's sandbox file system.Following is the code sample
var getSubDirectory = function()
{
subdir.getFile('demo',{create: true},function(fentry)
{
console.log(fentry);
},errohandler)
}
subdir is directory entry. subdir is returning properly, I am getting its output.But when i try to create file into that directory using getFile function, it throws security error.I have permission in manifest for the filesystem.write and filesyste.directory.I tried isWritableEntry() on subdir, its returning false.

Related

Trying to return a static file in web.py but getting "not found" error message

I have a web.py server hosted on pythonanywhere.com doing some handy things with python.
Now I'd like to just serve a straightforward html file from the same server i.e. just return the contents of a static html file to the client
The comments/answers below state that it should be possible, out of the box, to serve static files in the static directory, located in the same directory as the main python file which contains the following :
import web
urls = (
'/', 'hello'
)
app = web.application(urls, globals())
class hello:
def GET(self):
return 'Hello, Joe'
if __name__ == "__main__":
app.run()
The server above works fine, when I go to http://myhost/ it displays "Hello , Joe".
The directory static exists and contains a file small.jpg but when I try the url http://myhost/static/small.jpg it gives me "not found"
Previous text of question up to Nov 9th 2022 is below :
original question title : Trying to return a html file in web.py but getting "No template named ....." error message
So I've looked at the web.py documentation on serving static files and templating and I think the following code should work :
import web
render = web.template.render('static/')
# have also tried render = web.template.render('/full/path/to/static/')
urls = (
'/getlatlongEIRCODE', 'getlatlongEIRCODE', #other stuff
'/getlatlongGOOGLE', 'getlatlongGOOGLE', #other stuff
'/getmonthlyPV', 'getmonthlyPV', #other stuff
'/Tomas', 'Tomas',
)
class Tomas:
def GET(self):
return render.Tomas()
I have created a folder static at the same level as my file above (which works fine for the other scripts) and i have created a file Tomas.html in the static folder containing
<h1>Help me</h1>
However I get an error message when I go to https://example.com/Tomas
<class 'AttributeError'> at /Tomas
No template named Tomas
P.S. From the static files page it seems to say I should just be able to put the Tomas.html file in a folder called "static" and then access is via https://example.com/static/Tomas.html but that is not working (it returns "not found")
You're using a relative path to your template directory without paying attention to the working directory. See https://help.pythonanywhere.com/pages/NoSuchFileOrDirectory/
You're working too hard. 'static' is built in.
As the documentation says, http://localhost/static/logo.png will return the file logo.png from the existing directory static, which is relative to your webserver root.
Do not use render() for this (not needed). Also, do not list your desired file ('/Tomas') in the urls list (not needed).
Anything under the static directory can be accessed with the url https://localhost/static/...
"static" is hardcoded in the web.py server, so you cannot (easily) change this to some other folder. The suggestion in the web.py documents is to have nginx or apache host your application and use an Alias there to go to web.py static. (I think you can also add StaticMiddleware to your web.py application, but you'd need to investigate that yourself -- look at web.application.run()
The case of the disappearing /static/ directory was related to the fact that I'm hosting on pythonanywhere.com
Even though the web.py documentation says that the /static/ folder is plugged in by default, that's not the case in pythonanywhere and you need to expressly make the link between the url http://yourhost/static/ and /path/to/static in the Web part of the dashboard.

Downloading file from storage folder not working

I'm trying to download pdf file from public folder in my lumen 8 application. The exact file path is public/assets/attachments/resume.pdf. My code is
public function downloadResume()
{
return response()->download('public/assets/attachments/resume.pdf');
}
as per suggested here.
However the code is throwing following error:
What's the proper way to downloding the file ?

Get the current project directory from flutter integration test

Is there a way to get the current project directory in flutter integration test? This is a basic test setup as an example.
import 'dart:io';
import 'package:flutter_driver/driver_extension.dart';
import 'package:ivori/main.dart' as app;
import 'package:glob/glob.dart';
void main() {
// This line enables the extension.
enableFlutterDriverExtension();
print("Where the working directory? ${Directory.current}");
print("What's under the current directory? ${Glob("*").listSync()}");
// Call the `main()` function of the app, or call `runApp` with
// any widget you are interested in testing.
app.main();
}
Both of the middle two added lines Directory.current and Glob("*").listSync() are attempts to check/show the current working directory. The output from the above is:
$ flutter drive --target=test_driver/app.dart
Changing current working directory to: /Users/yuchen/Documents/MyDemoApp
Using device iPhone SE (2nd generation).
Starting application: test_driver/app.dart
...
...
...
flutter: Where the working directory? Directory: '/'
flutter: What's under the current directory? [Directory: './home', Directory: './usr', File: './.DS_Store', Directory: './bin', Directory: './sbin', File: './.file',
Directory: './etc', Directory: './var', Directory: './Library', Directory: './System', Link: './.VolumeIcon.icns', Directory: './.fseventsd', Directory: './private',
Directory: './.vol', Directory: './Users', Directory: './Applications', Directory: './opt', Directory: './dev', Directory: './Volumes', Directory: './tmp', Directory:
'./cores']
Not hard to see, the working directory is actually set to the root folder of the computer. Is there a way to get to the current project directory or src directory somehow?
The motivation behind this is to have some test data that will be used during the test but not in the app bundle. There are some discussions (fixes and work rounds) about unit tests in this long thread https://github.com/flutter/flutter/issues/12999. However, it doesn't seem to have a solution for integration tests.
In my case, I used ext_storage to access the device's storage. The path_provider plugin seems to only able to access the app's directory.
Here's a sample of fetching the storage path for Downloads.
/// Get storage path for Downloads
/// https://pub.dev/documentation/ext_storage/latest/
Future<String> _getPath() {
return ExtStorage.getExternalStoragePublicDirectory(
ExtStorage.DIRECTORY_DOWNLOADS);
}
Flutter test command accepts a parameter --dart-define which allows you to set variables
Running your test like this:
flutter test integration_test/test.dart --dart-define=projectRoot=$(pwd)
from the root of your project will allow your test code to access the projectRoot variable and get your files
const projectRoot = String.fromEnvironment('projectRoot');
// now you can access your files like you would expect
final file = File('$projectRoot/test_resources/test.json');
Note: Flutter sets the execution directory to the root of the file system only for integration tests, you don't need this workaround for regular unit (widget) tests

SL 5 file drag and drop app works when local, not when started from remote web page

I am working on an app that the user can drag and drop files and directories in to.
When I start the app from the debugger, either with or w/o debugging, the app works as expected.
When I try to use the xap in a page on a remote site, I get a Security exception.
foreach (FileInfo fi in files)
{
// _files.Enqueue(fi);
if (fi.Attributes == FileAttributes.Directory)
Attaching the debugger to the browser, I see:
+fi.Attributes 'fi.Attributes' threw an exception of type 'System.Security.SecurityException' System.IO.FileAttributes {System.Security.SecurityException}
"File operation not permitted. Access to path '' is denied."
1) Why does it work when started from the debugger?
2) How can I get it working outside of the debugger?
Thanks for any insight....

Create new file in user directory (with InstalledFileLocator on NB Platform)

How to create new file in a user directory on NetBeans Platform application? I used:
System.getProperty("netbeans.user", "user.home") + "/myfile");
But the NB IDE 7.1.1 told me that it is depreceated and I should use InstalledFile Locator instead. Ok, I tried this:
File file = InstalledFileLocator.getDefault().locate("myfile", null, false);
It works fine, if the file already exists. I cannot see any way, how to create new with the InstalledFileLocator. But the javadoc say, this method allows to get folder. So I tried this:
File file = InstalledFileLocator.getDefault().locate("myfile", null, false);
if (file == null) {
file = new File(InstalledFileLocator.getDefault().locate("", null, false), "myfile");
}
Again without success, the method locate now fails that it can't find anything (the "/" is forbidden and does not work too).
So my question is, how to corectly load in my NetBeans Platform application an existing file in the user directory (it is for writing also, so it should not be in the program directory) and if it does not exist, create it?
You could use Places.getUserDirectory().
File file = InstalledFileLocator.getDefault().locate("myfile", null, false);
if (file == null)
{
file = new File(Places.getUserDirectory() + File. separator + "myfile");
}
From the netbeans platform docs InstalledFileLocator should not be used to find resources on the system filesystem. To find data in the system filesystem, use the Filesystems API. Ex:
FileObject fo = FileUtil.getConfigFile(myfile);
if (fo == null) {
fo = FileUtil.getConfigRoot().createData(myFile,ext);
}
Probably the easiest thing you can do is to include a simple empty file (say "here.txt") in your module that will be installed in the user directory automatically. You can see an example of this here (see the section "Lessons learned: bundling files with your NetBeans modules").
Basically you include the file in the "release/modules/ext/here.txt" directory of your module.
When the module is installed the platform will install the 'here.txt' file included in your module in the user directory automatically for you, so you don't have to worry about this.
Once your module is installed an running you want to locate the file like this:
File hereTXT = InstalledFileLocator.getDefault()
.locate("modules/ext/here.txt",
"a.b.c",
false);
(Where "a.b.c" is your module identifier.)
And then from that 'hereTXT' file you can get the directory with 'hereTXT.getParent()', and you're all set.