Working on a project where we're using an XML of a user's iTunes tracks and play lists to integrate into other services. On Mac, this file is stored in the default location at /Users/username/Music/iTunes/iTunes Library.xml . Since we need users to be able to upload their own XML file, is there a way to write a script that pulls the file from that location as soon as they click an upload button (saving them from having to search and find it each time)? If so, is this something that can be done through Javascript (or through Rails, since we're using that as well)?
Thanks!
If you mean on a browser, no, you can't. The user has to select the file, you can't pre-select it for them. It's a security measure. If a web page could pre-select the file in an input type="file", it would be trivial to auto-submit that form, or hide the input and trick the user into submitting the form, or read the file via the File API and send it to a server — in all cases, stealing a file from the user's machine without their knowledge or consent.
Related
I am trying to allow users to upload pictures to the server.
I am trying to create a similar system to any website that has an 'attach' file or 'upload image' feature. All I need is to get the full path of the file select by the file dialog.
I tried using this for the file dialog with no success:
<input type="file">
This method does not provide the full file path, due to security reasons. My question is how can I create a similar input dialog to websites like tinypic, photobucket, etc.. that can help users input the full file path of a given image, into an input field?
I am aware that this cannot be done using the method above for security reasons, however, I have seen this done before on various websites without any problems, I was wondering what I had to do to implement a similar file dialog that helps fill in the text, which is a full file path, of an input field?
It is not possible to get the file full path on local machine using browser and javascript.
However, as you would like to upload the file to the server, the easy possibility I see is to use html form with input type file. You will receive the file on your http server when the form is submitted.
Here is a very good url http://www.cs.tut.fi/~jkorpela/forms/file.html that explains the whole process nicely.
I'm new to Django and want to give a user the ability to browse through their local files and "upload" them. However I do not actually want to store their files on my database, I only want to get the filename, path, memory etc of the file the user has selected. I have read through Need a minimal Django file upload example, and many more sites, but everything talks about uploading a file. Any advice would be appreciated!
Thanks
The only interface to local files available in a web browser is the File-picker, as if to select a file for upload. But, you don't have to upload the files! You can work with them in Javascript instead. See for example's Mozilla's documentation on "Using files from web applications".
Note that the Javascript File objects you get back have name, size, and [MIME] type properties.
Your client-side Javascript could poke these into a form, that the user then submits to your server-side Django application. Or, the client-side Javascript could put them into an AJAX action that submits them to the server-side Django application.
I'm developing an application that will allow the user to create his/her own data, and since I don't have a backend or a database, everything just lives on the user's session.
My ideal solution would be the following:
User works with the application, clicks on "Save", gets a download prompt, downloads a file to his/her filesystem
User clicks on "Load", a file input dialog gets shown, user picks his/her file, and the data is back again on the app.
I thought in using the FileSystem API, but it will just work on a sandboxed environment which defeats the ability for the user to work with the data in another browser.
I know I can simulate a download by just stringifying the data dropping it into a window to make a download. However, when I want to load this data again using input type=file, I don't have the ability to read the actual contents of the file, so it's a one-way path.
Some other apps usually just displays the contents of the file to the user and make the user copy/paste content, but I would like to simplify to the user.
Finally, I would like to support at the very least the latest version of desktop browsers.
What option would be the most suitable for this situation?
You should offer files for download, then read them from <input type="file"> using FileReader.
I'm relatively new to this
We have a requirement to save a file with out the use of the dialog box.
I was wondering if I can use AJAX or some other JavaScript to "Push" the file from the client PC being viewed in a browser to to some web service the client is running and have it save the file.
Do I get into cross site scripting issues or an issue I don't know about at present?
Thanks
With valums uploader script, users can drag and drop files (in certain browsers) to a button on the page.. so, yes, no dialog box, but it still requires user interaction. (I also know IE10 should be able to handle drag/drop functionality from one of their demos; so this kind of functionality is gaining ground).
I don't think you can upload a file without a dialog box. That would remove the user interaction, so it would be the same thing as allowing a webpage to select any file it wanted and upload it without user interaction - an obvious security flaw.
Generally, without a dialog box, no it can't be done.
HTML5 has a file API where the web app can store files on the local machine. But this access to the filesystem is sandboxed, so you get to access files only under your directory.
Why can't you do without a dialog box? Imagine you visit some site and it "uploads" files without your permission. That's a security FAIL. The dialog box is the user's authentication for the file to be uploaded.
I am taking a text file from user and then posting that file back to the browser using ajax storing the content in db and then showing the content back to user page using Jquery post response.
Now i want to something like this..
Read the text file from the user computer using javascript. Display the content and when he submits the page I will save the values.
Can't be done in pure JS for security reasons. You would need to have the user upload the file to your server, and fetch the contents back through Ajax.
If you use Flash or Java, you should be able to gain direct access to the file. If you speak Flash/Actionsript, maybe SWFUpload's source code (especially the new client-side resizing functions) can serve as an inspiration.
Update: This blog entry should help. Read and write local files with Flash Player 10
Update: To elaborate on the "upload and fetch" thing, if you do the uploading in an IFRAME, you could even have the upload script simply output the text file's contents. Because the iframe belongs to your domain, you will be able to retrieve its contents via JavaScript when the upload has finished. As long as you send a content-type: application/text it should be fairly safe from any malicious attacks.
If you're ok with Firefox 3.6 support only check out https://developer.mozilla.org/en/Using_files_from_web_applications, otherwise you should use Flash, Java or silverlight for this.
You won't be able to read a file in user's computer due to security issues.
Reading client files in javascript is possible with the new File API available in modern browsers. Check this site and its code: http://www.readfileonline.com/
However, before reading file contents in javascript, the user must explicitly select the files it allows to read. This is a security feature of the standard.