access local file with jquery in client side of a Django project - javascript

I need to access a local file on the client side of a Django project and read an xml file from the client's local disk. Like C:\\test.xml
I am doing this in a single html and script file and using Chrome --allow-file-access to get permission for this access and it works but when I move this code into my Django project and use this jquery script in my html templates, it does not work and shows cross origin request ... error.
Please help me. Why is this happening and what is the solution?
Thanks.

One viable option that would work and not set out security alarms all over the place, would be to use file form field on your page and ask an end user to give that file to you.
Then, you can use HTML5 File API and do whatever you need in javascript or send it to your server.

Related

copy file from one folder to another folder using javascript or jquery

I have a file path like this \\ptrisf02\group2\Engine_Follow\V2500-A5\V2500-A5_e-Archive\EV15159-02\Pictures_INC\INCOMING-LX\Oil tank.jpg in my database. I want to copy it another folder like T:\\Temp\\ when the button clicked in my jsp page. Is there any method to do this using javascript or jquery? I tried ActiveXObject but it gives me this error Automation server can't create object in IE.
There are two main issues you are going to run into with trying to use JS in any flavour:
Permissions and security.
JS is sandboxed.
The better way would be to use JS to fire an Ajax call which does the file copy/move for you using whatever server side language the web server is based on. That is provided that the web server actually has the permission to do so.

File Protocol Ajax Request

I have made a project whose structure is like this
When I run my index.html from firefox, it is working fine.
But I open it with my chrome it is giving CORS error.
Now my problem is that chrome doesnot support file:// protocol ajax request & as I have distribute to my project to others I don't want other to run on firefox only.
Internally I am using ajax call in project, to load the resources. Can Somebody suggest how to bypass that ajax call to load resources?? Is there some solution or any third party js which can help me.
Note: Please don't suggest to use XAMPP, apache etc where I can put my project and run as localhost for chrome as I don't want user to force to download these to run my project. Please give other useful solution where I can do some change in code & it works for everyone.
Here are the links from which you could understand my problem better.
Ajax in Jquery does not work from local file
AJAX code do not run locally
AJAX request using jQuery does not work
Embed the data directly into the JavaScript or HTML and read it from there.
The data isn't going to be changing based on user input or the contents of a database, so having it in a separate "http" resource doesn't bring huge benefits.
If you want to store the data in XML to make it easier to edit in your development environment, then write a build tool to bundle it up into an embedded format before distributing.

Save Javascript or Replace Javascript File in Chrome Developer Tools

Is there a way to replace a .js file in the website sources with a file on my workstation, or make a modification to a .js file and refresh the website to see the changes?
I am developing client-side JavaScript code against a SharePoint website on a server. I cannot create a local version of the website, so I need to modify the script, save the file to the server, refresh, etc. I do not have direct access to the server, and saving a file in a SP doc library or web part takes a lot of time between edits.
I can make small modifications using the dev tools while breaking on certain lines and applying snippets, but I am hoping for a better way.
Thanks!
If you have access the server that's hosting the file you should be able to replace or modify the JS file. Alternately you can use local hosting tools to test your file and then upload it to the server once you've confirmed it's working.
If you explain what you level of access to your host is we can offer better suggestions.

Is it possible to use the File JavaScript api to load a server side file?

A quick question, I recently checked out the new html5 File api for javascript. See it here. Is it possible to use it to pull in a server side file without ajax? I know there's a File object in JavaScript, could I do a "new File("serverSideStuff.xml");" with that?
From the API description -
Using the File API added to the DOM in HTML5, it's now possible for
web content to ask the user to select local files, then read the
contents of those files.
So no, you can't select server side files
No, it is only for local files, as I know.
It is not possible because the user must be aware of what your are loading, and is the user who can tell you what you can load or not.

Upload a file to an html page with no backend?

Is it possible to read the contents of an uploaded file (through <form><input type="file">) from inside javascript with no backend? I suppose it's possible with HTML5, but what about HTML4?
You can read (not upload - well, you can upload too, but that's like sending fan-mail to Edgar Allen Poe; nothing stops you but he won't be able to read it) from files if your script runs in a very trusted context.
If anyone on your network is browsing the web in a browser set to give that much trust, disconnect their machine from the network first, make their settings tighter second.
I don't know if I understand correctly. How about using something like uploadify together with jQuery. I guess you'll have to grant the webserver the privilege to write in the specified folders.
The security model will not let you unless you change the security to allow this.
http://www.mozilla.org/projects/security/components/signed-scripts.html
Can you elaborate on what you want to do?
I read the question as "How do I grab the contents from a file chosen using a file upload field and process it on the client without involving a backend/webserver".
I am thinking UniversalBrowserRead access for FF and HTA filesystem for IE for example

Categories

Resources