I am developing WinJs app and I want to create several files in my app installed location in order to navigate to them locally. When I am trying to create new file I am getting Access denied exception :
"WinRTError: Access is denied"
This is the code which I'm using for file creation:
var folder = Windows.ApplicationModel.Package.current.installedLocation;
folder.createFileAsync("index.html", Windows.Storage.CreationCollisionOption.replaceExisting)
Is there a way to allow this functionality, or is it just blocked for security reasons and there's nothing that you can do about it?
Craeting those files in local folder cause another issue that I want to prevent - that's why I am trying to create them in installed location.
Thanks
You can't do that ! this folder is a read-only.
But ... (if you have to do this)
You can write anithing in the localFolder
Windows.ApplicationModel.Package.current.LocalFolder
And write a lot of code to read this files that you created, to load them dynamically in your app
Related
I'm building a flask app called Neuroethics_Behavioral_Task.
I also have an s3 bucket called neuroethics-task. In the root directory, I uploaded a file called experiment.js and an image, test.png.
I followed the instructions in these two parts of Heroku's documentation about s3:
https://devcenter.heroku.com/articles/s3
https://devcenter.heroku.com/articles/s3-upload-python
The first link says the following about how to access assets you've uploaded to s3
After assets are uploaded, you can refer to their public URLs (such as http://s3.amazonaws.com/bucketname/filename) in your application’s code. These files will now be served directly from S3, freeing up your application to serve only dynamic requests.
So I have this line in the header of one of the html templates.
<script href="http://s3.amazonaws.com/neuroethics-task/experiment.js"></script>
I also tried to include the image from copying the path directly on s3 (which is different from the heroku docs). Here's that line.
<img src='s3://neuroethics-task/test.png'
The issue is that nothing happens when I access the web page that's supposed to use the javascript from experiment.js currently when I'm trying to use the Flask application LOCALLY.
I suspect that maybe things will work if I push to heroku... But I need to get a local debugged solution up and running first and foremost. So i need to figure out how to correctly reference these files.
I had gotten error messages before when I used src= and when I had variants of the url's prefix. But now, nothing happens when I get to the webpage that's supposed to load experiment.js. experiment.js uses a javascript framework called JsPsych that basically works like a static application -- no redirects occur from jspsych. You have to create an html template for flask's sake, but all you have to do for that template is include the reference to the experiment.js file.
Since experiment.js just isn't loading yet, and since there's no other html on that template because all of it is within experiment.js, nothing happens.
I have my environmental variables set:
$ export AWS_ACCESS_KEY_ID=jhdfshfjskdhfj
$ export AWS_SECRET_ACCESS_KEY=jlsjfklksfjlfh
I'm not sure about what permissions settings I need on s3. For my bucket, I have
Block public access to buckets and objects granted through new access control lists (ACLs) -- Off
Block public access to buckets and objects granted through any access control lists (ACLs)-- Off
Block public access to buckets and objects granted through new public bucket or access point policies -- On
Block public and cross-account access to buckets and objects through any public bucket or access point policies -- On
So... what's going wrong here? I just want my javascript to load at least.
I am creating a local web application where I want to be able to clear the content of my directory.
How can I remove the files from a directory without deleting the directory itself?
I need it to be empty.
Is it better to remove the whole dir and create it again?
If javascript can delete directory contents, that would a pretty big security concern. Javascript by itself cannot delete system contents. You can make an AJAX call to the server which in turn can delete the files
For deleting the files of your local system you need a server-side scripting language. Vanilla Js cannot do that for you as it is a client-side scripting language.
If you are using Nodejs, as it is a server side you can definitely do that using unlink() for deleting file asynchronously or use unlinkSync() for deleting file synchronously you can learn about how to use that function here...
Demo code unlinkSync() -
const fs = require('fs');
let filename = "D:\\temp\\temp.zip";
fs.unlinkSync(filename);
I am attempting to load a series of Images from a Shared Dropbox Folder like so:
function getSprite(raw) {
var sprt = new Image();
sprt.crossOrigin = '';
sprt.src = 'https://dl.dropboxusercontent.com/s/k1v7iv85vntx107/AABOD-CfE3A5sQo0RPPmRmmJa/ground1.png' + (raw ? '?raw=1' : '');
return sprt;
}
The folder is shared, and Dropbox says that 'People with Link can View'. I have tried to do the same with Google Drive, but I get a Cross Origin Error there.
EDIT: I just tried to share one of the files individually, and it worked. DO I have to now go through and do this for each file in the folder? I thought If I just share the folder I should have access to all its contents.
ERROR MESSAGE:
GET https://dl.dropboxusercontent.com/s/k1v7iv85vntx107/AABOD-CfE3A5sQo0RPPmRmmJa/characters/triggerman/up.png?raw=1 403 (Forbidden)
It looks like the original shared link you had was:
https://www.dropbox.com/sh/k1v7iv85vntx107/AABOD-CfE3A5sQo0RPPmRmmJa?dl=0
This is a shared link for a folder. Note that you can't just modify it directly to get shared links for individual files inside that folder though, which is what you appear to be trying in your question.
To get the individual files, you have a few options:
Manually get the shared links for each file via the Dropbox web site, as you mentioned.
Use the API to individually but programmatically get shared links for each file: https://www.dropbox.com/developers/documentation/http/documentation#sharing-create_shared_link_with_settings
Use the API to download the files in the original shared link by specifying the path inside the folder: https://www.dropbox.com/developers/documentation/http/documentation#sharing-get_shared_link_file This is likely closest to what you're looking for.
I don't think this has much to do with JavaScript. Go Incognito and take a look at it because all I can see is a 403 error from my browser.
I'm working on an HTML/javascript app intended to be run locally.
When dealing with img tags, it is possible to set the src attribute to a file name with a relative path and thereby quickly and easily load an image from the app's directory. I would like to use a similar method to retrieve a text file from the app's directory.
I have used TideSDK, but it is less lightweight. And I am aware of HTTP requests, but if I remember correctly only Firefox has taken kindly to my use of this for local file access (although accessing local images with src does not appear to be an issue). I am also aware of the FileReader object; however, my interface requires that I load a file based on the file name and not based on a file-browser selection as with <input type="file">.
Is there some way of accomplishing this type of file access, or am I stuck with the methods mentioned above?
The browser will not permit you to access files like that but you can make javascript files instead of text files like this:
text1.js:
document.write('This is the text I want to show in here.'); //this is the content of the javascript file
Now call it anywhere you like:
<script type="text/javascript" src="text1.js"></script>
There are too many security issues (restrictions) within browsers making many local web-apps impossible to implement so my solution to a similar problem was to move out of browsers and into node-webkit which combines Chromium + Node.js + your scripts, into an executable with full disk I/O.
http://nwjs.io/
[edit] I'm sorry I thought you wanted to do this with TideSDK, I'll let my answer in case you want to give another try to TideSDK [/edit]
I'm not sure if it's what you're looking for but I will try to explain my case.
I've an application which allow the user to save the state of his progress. To do this, I allow him to select a folder, enter a filename and write this file. When the user open the app, he can open the saved file, and get back his progress. So I assume this enhancement is similar of what you are looking for.
In my case, I use the native File Select to allow the user to select a specific save (I'm using CoffeeScript) :
Ti.UI.currentWindow.openFileChooserDialog(_fileSelected, {
title: 'Select a file'
path: Ti.Filesystem.getDocumentsDirectory().nativePath()
multiple: false
})
(related doc http://tidesdk.multipart.net/docs/user-dev/generated/#!/api/Ti.UI.UserWindow-method-openFileChooserDialog)
When this step is done I will open the selected file :
if !filePath?
fileToLoad = Ti.Filesystem.getFile(scope.fileSelected.nativePath())
else
fileToLoad = Ti.Filesystem.getFile(filePath)
data = Ti.JSON.parse(fileToLoad.read())
(related doc http://tidesdk.multipart.net/docs/user-dev/generated/#!/api/Ti.Filesystem)
Please note that those snippets are copy/paste from my project and they will not work without the rest of my code but I think it's enough to illustrate you how I manage to open a file, and read his content.
In this case I'm using Ti.JSON.parse because there is only javascript object in these files but in your case you can just get the content. The openFileChooserDialog isn't mandatory, if you already know the file name, or if you get it from another way you can use Ti.Filesystem in your own way.
I'm a beginner! I need to read data inside txt files in a local folder offline. I know the folder path, but I don't know the name of every single file.
C:\mypath\first.txt
C:\mypath\second.txt
C:\mypath\third.txt
...
To read a sigle file now I use:
$.ajax({url:"C:\mypath\first.txt",
success:function(result){
//...code for storing the data in a variable...
}
});
How can i read multiple file at once without know their name? something like:
$.ajax({url:"C:\mypath\*.txt",
success:function(result){
//...code for storing the data in a variable...
}
});
Thank you for any help!
You can use a file picker control (ie, <input type="file" multiple />) in a supported browser and have the user select the set of files to iterate. User input is the only way to get the list of files - you can't just go mucking about in a user's file system over the internet. All you can learn about the user's system is what the user tells you (eg, through <input type="file" multiple />).
And even then, you won't be able to read the file with a simple Ajax request. Same origin policies apply to local files. It may work if you test it on your own machine, but as soon as it hits the web, it will fail.
The only way to look through a client file system without user interaction is by using a Scripting.FileSystemObject ActiveXControl on windows in a non-internet based HTML Application (.hta file). So, since you don't want to use ActiveXControls, user input is your only option.
Edit: If you are creating a FireFox add-on, you can access the file system. See the documentation at mozilla.org for details.