Does method writeFile work in IE8? - javascript

I am writing Dropbox web-application and use Client Library for the Dropbox:
https://github.com/dropbox/dropbox-js.
For uploading file choosen by user I use method writeFile. Html object File(< input type=file >) is passed as parameter data. It works fine in FireFox.
It is said that this library is tested against IE9 and IE10.
Does method writeFile work in IE8?
If it does not work in IE8 then is there way to use html form for uploading file to dropbox?
Dropbox docs does not give example how to upload file by html form.
Is there some example?

writeFile takes the contents of the file, not an HTML input tag. See http://coffeedoc.info/github/dropbox/dropbox-js/master/classes/Dropbox/Client.html#writeFile-instance.
This means your JavaScript has to have access to the actual contents of the file to use writeFile. The HTML5 File API might help here, but it certainly doesn't work in IE8.
I think this means you'll need to upload the file to your own servers (via a standard form submit) and then transfer the file from there to Dropbox.
EDIT: Remove a clause claiming general poor support for File API. It looks like it's not that bad: http://caniuse.com/#search=file%20api

Related

forceIframeTransport and context.Request in HttpHandler

I have used blueimps jquery file upload plugin to upload files in WebForms application. The plugin sends files to the http handler which parses context.Request.InputStream and uses context.Request.Form["param"] that was set with formData part of the request.
Everything works fine in modern browsers, but as soon as forceIframeTransport option is needed (IE 7 for example) all those Request properties are empty.
How can I get the file stream and form data in that case?
The answer was to include the jquery.iframe-transport.js file. Without that file the inputs were not created (and therefore not submitted).
Also I had to change the way formData is treated (as simple formData.someProperty was not there - you have to use formData[0].name / value)
and the response was returned as a html page (instead of plain json).

Trigger file upload via Javascript only

I want to write a browser add-on that automatically upload file on the page. So this will be done in pure Javascript.
This is what I have / know:
input#someId of the file upload input
File name and location in the computer
I am trying to "hardcode" in the console for now as a "Proof of Concept" but I cannot get it to work.
I have tried these two methods:
inputElement.click() as inputElement is the querySelector of that input.
Use initMouseEvent from what's the equivalent of jquery's 'trigger' method without jquery? but gave me error Uncaught TypeError: Cannot read property 'dispatchEvent' of null
So my questions are:
How to trigger click input of file upload element?
Better: how to process the upload completely? Basically pass the filename+location for upload to start (like when user clicks OK to open the file from the dialog)
UPDATE 1:
I was reading this http://www.thecssninja.com/javascript/fileapi
Maybe uploading file from File System is not possible. How about these alternatives:
We can grab a file from url (http)
The file is just image and in Javascript memory (base64)
Anyone of the above should be OK if they can be automatically upload and bypass the dialog box and search the file via local File System. I am thinking what if the image DOM or even canvas can be just dragged?
As people commented, you cannot do that. For security reasons, you have absolutely no access to programmatic fill an file input. Think about it, some dude could add a simple script to steal files from your computer and you wouldn't even know!
As far as I know, can't be done.

Download a file by changing window.location w/ Safari

I have an offline html file that generates and saves a CSV by setting window.location to
data:text/csv;base64,Intfa2V5fSIsInt...
However, in Safari this just brings up the CSV in the browser.
Setting the url to:
data:application/csv;base64,Intfa2V5fSIsInt...
forces Safari to download the file - but it gets a generic file name of just 'Unknown-3'. Is there a way to specify the file name?
First, a warning:application/csv isn't a valid MIME type, so the fact that it "works" for you in this case is purely an implementation quirk that could very well change in the future. (For example, Safari displays application/octet-stream, which I'd expect to download.)
HTML5 does have a new <a download="file.name"> attribute. This forces the browser to download the file to disk; it uses the attribute's value as the default file name. It does work in conjunction with a data URI or a blob URI. (Demo)
However, it is currently only supported by Chrome (14+). Safari 5.1 ignores the attribute.
A possible alternative is to use the Filesystem API, but that gives you a sandboxed folder to work with. You can't—for example—save a file directly to the user's Documents folder. Instead, you can write a file to the sandbox and then redirect to file on the new filesystem schema:
location.assign('filesystem:http://example.com/temporary/somefile.csv');
This should invoke the UA's download mechanism (with the right filename!), but I haven't tested this, so it is possible Safari will just display the file anyway.
According to the RFC 2397 no. There is no way.
Also read this related question.

JS code to display file path on a hidden upload file field

I used the Shaun Inman's method to create a customized "upload file" button, and it works just fine.
Trouble is, this method doesn't display the file path that the user has uploaded.
Can anyone help me with a simple JS code to have the file path displayed when selected.
Newer versions of browsers do not send up the file path for security reasons, that is why you are not seeing it.
IE8 value depends on security zone

Save XML file on my machine with XMLDom object save()

I'm not able to save to the xml file on my machine.
I have noticed that node value is changed temprorily but not permanent in xml file.
P.S : This is only a simple HTML file with javascript
It is giving me an error "Permission Denied"
function viewBookDetails() {
var xmlDoc = xmlLoader("cart.xml");
//var x = xmlDoc.getElementsByTagName("dogHouse")[0];
var x = xmlDoc.documentElement;
var newel = xmlDoc.createElement("essy");
x.appendChild(newel);
alert(x.xml);
xmlDoc.save("cart.xml");
}
is it not possible to save xml file on my machine?
Thank you,
In general, browser JavaScript has no I/O API and cannot read or write to the client filesystem since that could be a security loophole. I haven't seen or used the save() method before but it looks like it's an IE specific extension to the XML DOM. If you must use it, this thread might provide the solution, the answer that worked for the OP there suggested:
I haven't proofed your code but here is something you might want to try. I am taking a shot in the dark that you are using this on a Windows OS since you are using IE and from the sound of the error. Just take your html file that you have and rename it the whatever.hta and it will then be able to write to the xml file and save.
Also, the documentation for the method says the following for when the argument is a string (as in your code snippet):
String
Specifies the file name. This must be a file name rather than a URL. The file is created, if necessary, and the contents are replaced entirely with the contents of the saved document. This mode is not intended for use from a secure client, such as Microsoft Internet Explorer.
From the forum posts (links below) that deal with the same issue, I gleaned the following:
This is an IE specific extension and so will only work in IE
There are obviously security restrictions in place so you shouldn't be able to do this 'out of the box'
One workaround that crops up often is to rename the file extension to .hta (Hypertext Application) instead of .html
I'm not sure but there might also be some workarounds by changing the permissions for the security zones your application runs in
References:
http://www.codingforums.com/showthread.php?t=25048
http://p2p.wrox.com/xml/4053-error-using-xml-save-method.html
http://www.daniweb.com/web-development/javascript-dhtml-ajax/threads/204995

Categories