I'm creating an application using processing.js and hosting the result via dropbox public folder, the idea is to use a .txt file generated via that platform to comunicate certain data to a local 3d modelling enviroment (rhinoceros/grasshopper), is it possible to write to a .txt file hosted in the public folder in dropbox directly from the sketch running in the web?
I mean, using: saveStrings("test.txt","this is an example");
the html containing the sketch, the .txt file and the sketch file itself are all stored in the same public folder in dropbox, you can see the site here: https://dl.dropboxusercontent.com/u/97841548/kinetica%20App/KineticaAppHTML.html
thanks in advance
You can't directly access your local filesystem from a web page like that, and you don't get write access to your Dropbox account just by virtue of the KineticaAppHTML.html page being hosted on Dropbox.
One way to do this however would be to use the Dropbox API. You could either proxy the file writes to a server you control and then have that server make the API calls to Dropbox, or you could use the Dropbox API directly from JavaScript on your KineticaAppHTML.html page.
Dropbox offers a JavaScript SDK you can use:
https://www.dropbox.com/developers/datastore/sdks/js
There's a tutorial here, though it focuses on datastores functionality and not files:
https://www.dropbox.com/developers/datastore/tutorial/js
The basics for authenticating the user are relevant though.
Once authenticated, you can use this method to write new contents to the file in your Dropbox:
https://www.dropbox.com/developers/datastore/docs/js#Dropbox.Client.writeFile
Note however that this strategy only results in you yourself, i.e., in your own browser, being able to make Dropbox API calls. If you want other users to use this to, this setup would have them connecting to their own Dropbox accounts. If you need them to connect to only your own account, you'd need to host and use your own actual web app, like I mentioned earlier, where you could safely make API calls to your own account. (You could technically avoid this by embedding an access token in your web page, but this is highly discouraged due the security implications there.)
Short answer: no.
Webpages in your browser do not have read/write access to your file system. Only the web.
Long answer: yes, but not the way you describe.
If you have a server running with a RESTful API that you can call by URL (like any other API on the web), then you can use any "ajax" approach there is to communicate with that, giving it the data it needs to generate those files, and making it responsible for putting them in the right dropbox folder.
Related
How can I reach a HTML file over FTP stored on Firebase hosting. i.e. on how can I call ftp://your_ip_address/bridge.html if bridge.html is hosted with Firebase?
Why do I want to do this?
So I have a website running WebRTC for camera access. I've been getting some complaints from users about how WebRTC is not available in apps (i.e. UIWebView / WKWebView don't support WebRTC). The best solution I can think of is to make a pop up that takes users to Safari in this instance. Detecting this scenario is quite straightforward. The issue is really opening Safari. I found this solution on how to do this, however, it requires that I make an FTP request to a server. I'm using Firebase for hosting so I don't really know how to access the level of filesystems. Is there another way to set this up or something I can do on Firebase to get to reach a HTML file over FTP from Safari URL schemes? If not then is the only alternative for me to get a separate FTP server and store the file there?
Firebase Hosting does not implement an FTP server, so you can not interact with it with FTP client commands. If you must use FTP to read from/write to your hosting provider, you may want to look at other services that do support that requirement.
I have AngularJS (1.2.16) application which works on Tomcat 8.0.x I need to add following feature: create a new tab in the application (no problem) and allows to user to select concrete from select box on previously implemented new tab, file from HDD (directory is given but outside from Tomcat) and preview (PDF file). How to connect those two worlds? I have backend also.
I have found very similar question- Simplest way to serve static data from outside the application server in a Java web application but I do not understand how to get in UI a list of files from given dir. There are any best practices on that?
EDIT: I have found also possible duplicate, so you suggest to serve all files under URL? Is it safe? Is it the only one solution?
Security considerations
Providing read/write access to a filesystem folder from an application server is always a bad practice.
It should be considered if the web application will be accessed from internet.
In case we need to handle this kind of situation the better think to do is to understand which information we need to have and to modify, and wen wrap those information inside a specific API that allow to work on strictly what we need.
Or we could have an operation approach which consists in the hardening of the server and the folders that should be accessed in a way that any threat will be contained.
The solution part
This answer was proposed for duplicate of: Simplest way to serve static data from outside the application server in a Java web application.
But this part just explain alf of the requested solution.
The answer here explain how to configure an extension of the default servlet from a custom folder in Tomcat:
You have to act on the conf/server.xml:
<Context docBase="/path/to/files" path="/files" />
Here you configure a folder in a way that Tomcat will access, and connect it to a path that could be requested on the HTTP requests (http://mytomcatserver/files/).
Now you need to configure the web.xml to connect a specific servlet to this path, to be able to handle the folder content.
Once you have your servlet and your Tomcat properly configured it's time to access the folder and files.
This could be done as explained int the answer Display list of files in webpage using servlet.
In short, you cold access the folder with plain java:
File filesFolder = new File(req.getSession().getServletContext().getRealPath("/files"));
And then with the method File.listFiles() you could get the list of files in the folder.
With File.listFiles() you could also add filters that allow you to hide files you don't want the user could access.
I have found several threads where the same question has been asked, but I suspect that the top answer in most of them are outdated.
My problem
I have a frontend javascript app communicating with an oauth authenticated API. This API contains files I want my users to be able to download. Because the API requires authentication, I can not show the user a regular link in order to initiate the download.
Instead, I have to send a XHR-request to initiate the download (so I can add the necessary authentication header).
In my case, the files will usually be pretty large (>1GB), so keeping them in memory is not a solution.
Reading this article, I'm wondering if it might be possible to stream the file from the API to the filesystem through the Javascript file API. Does anyone have a suggestion on how I might make this work?
Isn't this a pretty common problem in 2016?
It is somewhat hack-ish, but I've used it before and it works wonders.
From Downloading file from ajax result using blob
I need to implement a mechanism in order for a remote web application to communicate with a local desktop (WinForms) application that I cannot modify nor have the source of (except by decompiling). This happens by writing a file to the temporary folder that the desktop application will consume, and waiting for that application to "return" by writing another file into temp folder. Folder has to be temp folder.
Question
Is there a Javascript way to access the file system in a non sandboxed way, even by setting specific browser configuration options?
Environment
The application runs on a private LAN where all computers trust each other within the same AD domain. Plus we are theoretically allowed to map any network drive on any computer. Working in the trust zone, we don't have to care about most security concerns.
Background explanation
I have a PowerBuilder desktop application that I need to "port" to web (using J2EE) and install to a separate server, local to the same LAN. This application (named GP) currently starts a process of the child application (GC) that will not show any UI, instead it will listen for two files on a temporary directory.
When GP needs to open a window from the GC process, it will write two files: GP_to_GC.txt with a syntax I have documentation of, and GP_to_GC.flg that serves as flag file. GC will delete both after retaining and parsing the content of txt file, thus showing the appropriate UI form based on input.
The "return" is exactly the opposite. GC will write a pair of GC_to_GP files to temp and GP will refresh its views.
How can I do this with JavaScript?
Based on what I'm reading, you are porting a Desktop based Java EE application to a web application? If so, then you can continue using Java and access the folder that way; no need to use JavaScript.
What is unclear is that you're saying you can't modify anything, yet you're trying to port an application. Which is it?
If you can't modify anything, and the only thing you can do is drop JavaScript into an existing web application, then your solution is rather simple:
Create an HTTP API application that sits somewhere that has access to those folders, and issue a POST request to that API that will then read and write to the file system. It can be in any server side language you choose: Javascript (Node.js), C#, Java, PHP, whatever. It simply needs the ability to access the file system through the webserver, and most frameworks provide that capability.
I can't give you any code because you haven't mentioned which server side language you want to use to accomplish this approach.
Pardon me if I am asking something really stupid. But this is what I want to implement as per my new role as a analytic Implementer. Some of our files (Mostly pdfs) are stored on a webserver (CDN server) to reduce some load of the application server.
We provide links to these file to all our users across the world. What I want is to track these file download whenever they occur. So I just wanted to know is there any way by which I can call a function or a routine from where I can make those tracking calls ?
Not really.
If you are using a 3rd party web hosting as CDN, then you could simply get the Analytics reports using whatever tool your host offers.
If you are running your own hosting box, you could install almost any analytics software on it to monitor access. Just one example is provided here: http://ruslany.net/2011/05/using-piwik-real-time-web-analytics-on-iis/
The clean simple way, however, would be to have a simple web application running on that CDN server that accepts file requests and then returns the file. The advantages are that you could:
record whatever statistics you wish off it.
use widely available tools like Google Analytics
make dynamic decisions, one example of which is deciding version of file sent based on factors like user bandwidth, etc.
transparently handle missing files and path changes, so links will be valid forever
send different caching headers for different files
implement very simple access control and policy based restrictions