Rename and move files in local system using website - javascript

I am developing a website with frontend react and backend as django where users can generate names of files in a particular format. Now this files will be in their local system or their local servers we can say. I need to rename the file and move that to a source folder. Is that possible using a website? I have heard this is possible but now sure how. Anybody knows how this can be done?

Browsers accessing the local files system is considered as a security threat!
Imagine websites having the freedom to access all your files and images!
however for certain use-cases, this can be enabled on the browser itself, to enable websites from accessing file system.
however it is supported by google chrome only (as far as i know) you can use the FileSystem.API you can check this here Can i Use: FileSystem

Related

Cant open local file by Chrome or Edge for Japanese environment

I'm trying to develop HTML base editor equipped with browsing local files function.
I know basically that is restricted by browser to open local files.
However I found out some method doing this activity.
using path begin from "localexplorer://" it works perfect for English path name.
But when I use Japanese folder name or file name it becomes error.
I tried to convert SJIS format that file names but this is not work.
Here is code.
[![error[![\]\[1\]][1]][1]][1]url = 'localexplorer:' + event.target.innerText;
array = str2array(url);
sjis_array = Encoding.convert(array, "SJIS", "UNICODE");
sjis= Encoding.codeToString(sjis_array);
window.open(url, '_blank');
According to browser security, javascript is only allowed to run in the sandbox, you cannot read or write arbitrary files:
JavaScript and the DOM provide the potential for malicious authors to
deliver scripts to run on a client computer via the Web. Browser
authors minimize this risk using two restrictions. First, scripts run
in a sandbox in which they can only perform Web-related actions, not
general-purpose programming tasks like creating files.
If the user selects a file via <input type="file">, you could try to read the content of the file through FileReader API, like this case: How to open a local disk file with JavaScript?
If you need to interact with files on the user's local device or a user-accessible network file system, you can try to use the File System Access API. And this must be done in a secure context, and must be called from within a user gesture. You can also read this article to learn more about it:The File System Access API: simplifying access to local files.
Thank you for your response, I solved this issue by Forefox plug in extensions, it seems like chrome did not support this functions even if there is plug in extensions.

Possible download / upload manager embedded on html page with access to local filesystem

As the title indicates i want to have a certain application get access to the local file system. To describe why i will illustrate my situation:
I am a running a IIS WebApplication with the C# MVC 4 Framework as backend module. The site solely consists of HTML, CSS markup and some JS. The page will be loaded in IE11+ (Edge) only. For the standard procedure of displaying and accessing data from as well as sending data to the server this works quite fine.
On a certain page I want the user to be able to upload a file using a simple file dialog, like the one you can initiate with a simple <input type="file"> tag. I also want to offer the posibility to download files from the server but need to know where files has been saved / will be saved to.
As described on a lot of different websites, just like this one here, the HTML5 File API does a great job but will not be able to return the full qualified filename including the local path directions, same for JS accessing the file object.
As my research confirmed HTML5, JS and also SWF (Flash) will not report detailed information because they are all sandboxed applications or restricted by RFCs. I already unterstood and appreciate the effort to secure my trips to internet.
But in this case do need the paths where a file was upload from and the file has been downloaded to.
So my question is, what is the best way to expose the full path directions for a up- as well as downloaded file to report them back to the server?
Is it possible to embed a SWF object inside HTML which will run inside an Adobe AIR sandbox or is a signed JAVA Applet still the one and only solution to accomblish this security breaking task?
A solution i would also apreciate would be the possiblity to ask the user to get access the file system, like you grant access to the web push service to receive notifications.
Also if there is a possible solution which may suite my circumstances please let me know by adding some simeple examples / revealing some factful links, thanks in advance.

how get list of files in a folder using javascript

I am working on project for desktop application. I am using Qt controls with visual c++.
I am loading an html file in the QWebView as,
m_pWebView->load(QUrl("../../../demo/index_Splash_Screen.html"));
Now, what i want is, say, I have some .zip files in my location "c:\demo", I want list (or array of file names) of the files present in that directory.
How can i do this through javascript ?
PS: I went through this link, but it didnt match my requirement. I have not worked with of html, javascript and jquery. Please help me.
I'm afraid you cannot access local files or directories using javascript due to security issues.
Edit: I hadn't thought about the file api so thought for a moment this might not be true, but without some user input to give permission, this still cannot be done.
This question has a good response from PhilNicholas:
I'm afraid I may be the bearer of bad news for your design: The action
you are requesting expressly violates the security model as specified
in the File API spec. The client implementation of FileReader() must
make sure that "all files that are being read by FileReader objects
have first been selected by the user." (W3C File API , 13. Security
Considerations: http://www.w3.org/TR/FileAPI/#security-discussion).
It would be a huge security risk of browser scripts could just
arbitrarily open and read any file from a path without any user
interaction. No browser manufacturer would allow unfettered access to
the entire file system like that.
Thinking about it however, if it is all being run locally, you could use ajax to query a server side script that could return the directory you request.
If it is a Windows application then you could access the local filesystem by using ActiveX objects. You might have a look at this link Reading a txt file from Javascript
Note that activeX usage is possible only when using IE as browser/engine; I used to need it a while ago for developing an HTML application (.hta files).

Can I pass a file into the browser then manipulate it with javascript?

I understand that javascript running in the browser would not be allowed to access a local file system directly, it make sense and I am not looking for a way to violate that.
However are there any safe and kosher ways to grab files from the local system for the browser to use? Would these methods be platform specific? Would I be limited it what kinds of files and would access have to be granted on a per file basis?
What I am thinking about is when you upload photos, it will open a system level dialog and then eventually present that file to the browser for the browser to send to a remote server via http. Would it then be possible to pass a file in to the browers local memory/ give the browser permission to read it as it were to be upload but instead of uploading it somehow pass over to java script and allow it to manipulate it client side much in the way you can manipulate files with server side javascript?
The reason I am asking is because I have recently become interested in browser-based file manipulation programs, their feasibility and what could be done with them in a Chrome OS type environment. Just out of curiosity then any idea of it being practical any time soon.
edit: attempted to clarify and make my question more direct.
Use the File API (MDN has a tutorial) but be aware that it is a new specification and has limited browser support.
It allows files selected in an <input type="file"> to be accessed with client side JS.

Javascript: Listing File and Folder Structure

As I have read, it is not easy for JavaScript to modify files on client PC. I am working on a web based file manager and would need to know the following:
Can JavaScript list files and folder structure on a client PC?
Can JavaScript list files and folder structure on a server?
If your answer is no, that Java Scipt can not list files and folders say on client's or server's C:\ drive, than would CGI script be the only solution?
Browser JS reading client PC's files: Depends
For a security reason, you can't access the files on the user's PC without the user's consent.
That's why the FileReader API is created around the file input box <input type="file"> and a drag-n-drop area since the whole idea is to "access the file with user's consent". Without the user intentionally putting the file for access, you can't access it at all.
Server-side JS reading own server's files: Yes
As for server, if you meant access the server using server-JS (NodeJS or Rhino), yes you can (How else would it serve webpages anyway?).
Browser JS reading own server's files: Depends
Accessing the server from the browser using JS works if you have an API to read files from it.
Browser JS reading other server's files: Yes, with a catch
To access other server's files without some API, you could resort to creating a web scraper or a web-spider that runs server-side (since browser can't cross domains due to the same origin policy) and have an API exposed to your browser.
However:
you can't crawl to all files as some may be restricted from outside access.
the public appearance of the structure could be different from the internal structure, especially if the site uses segmented url scheme
sites using query strings to generate pages cannot be crawled easily due to the number of permutations it could make, thus some pages might be unreacheable.
CGI won't be a solution either, as it only has access to the filesystem of your server, not that of the client visiting your site. The only way to access your client's filesystem from javascript seems to be the File API, which apparently is not implemented by many browsers.
It's a cludge but you could resort to a java applet or the dreaded active-x control.

Categories