I have a .NET web service that takes a byte array.
I have a GWT client where I want the user to select a file using the FileUpload control and send it to the web service via HTTP stream.
The file upload control contains a method to get the file path of the selected file. How can I then get that file and convert it to a byte array?
I'm open to suggestions on how to get the file to my web service, not quite sure the Byte array will work...
If you want to convert the file in GWT, meaning in the browser. It's not possible to do in the browser using only JavaScript. FileUpload is a html input type file upload can only send the file to a server as in submit a form. For security reasons browsers can't read files from your file system. (You could use a plugin like a flash plugin to get it to work, although I have no examples at hand).
If you want to send the file content to your webservice, you need to or upload it directly to the webservice or send it to another server, convert it and from that server submit it to your webservice or write or find some (flash) plugin that does it for you.
This link maybe helpful yo you How to convert a byte array to a string, and string to a byte array with GWT
The String(byte[] bytes) constructor and String.getBytes() method are not implemented by GWT JRE emulation String class.
This is not possible purely in Javascript(yet) but could be done with flash or a signed applet. Personally what I would do is create a signed applet that would be somewhere on the page but not visible. When the user selects a file to send to the server you would get the file location from the input and send it to the applet which will load the file and return the data to Javascript as a byte array. If you are flexable with changing the web service to accept multi-part form data then you can do so and just include the file upload field as part of a form and submit the form. Now what you want to do is possible with HTML5 and a demonstration can be seen here, so if you are capable of specifying that the users be using at least a semi-HTML5 compliant browser such as FF3.6 or Chrome 6 you may be in luck.
Related
I'm using parse as my backend and would like to use the rest api to store files.
I've already successfully tested creating new data with the curl request here https://www.parse.com/docs/rest#files Now I would like to see what files I have on my parse.
I don't see any view for these in the data browser. Maybe there's a way to get a listing via a get request? How do I list the files stored on my parse backend?
Note that the column type in the parse data browser will be 'file' denoting 'pointer to a file in the parse CDN'....
treat that like a third party CDN where you also, do not have the 'fileList' capability u ask 4.
live with what u get from the parse browser's inclusion of the pointer, click the field in the browser and , depend on your OS/browser/plugins, it will automatic download/play the file depending on the MIME type you supplied in the headers when u uploaded it.
Remember that you can use the parse dashboard to ask it to delete or GC any files no longer pointed to by active class.rows.
IMO - its not hard to live without what you've asked for as long as you know the other features parse includes with these file type pointers/ refs.
i'm beginner with GXT and i'm wondering if there is a way to parse a file and extract some informations without uploading it.
i created a formpanel that contains an uploadFile form but i don't know waht's next, how to get the complete path of the file so i can read/write with java io or how to retrieve the file or is there an alternatif solution, thank you.
Best Regards.
You can do it in some modern browsers using bleeding edge HTML5 apis for which you would need to use GWT JSNI code. There are no api's from GWT team as is.
HTML5 FileReader
FileReader includes four options for reading a file, asynchronously:
FileReader.readAsBinaryString(Blob|File) - The result property will contain the file/blob's data as a binary string.
FileReader.readAsText(Blob|File, opt_encoding) - The result property will contain the file/blob's data as a text string.
FileReader.readAsDataURL(Blob|File) - The result property will contain the file/blob's data encoded as a data URL.
FileReader.readAsArrayBuffer(Blob|File) - The result property will contain the file/blob's data as an ArrayBuffer object.
Example of GWT wrapper over these -
https://github.com/bradrydzewski/gwt-filesystem
You can read about it more from here - How to retrieve file from GWT FileUpload component?
IMHO you cannot read it .
Due to security reasons javascript(gwt) doesn't have access to the system drives files.
http://en.wikipedia.org/wiki/JavaScript#Security
see Opening a file in local file system in javascript
In order to get the file you need to make a server call.
Instead you can do your validation server side and throw proper messages to user.
P.S : i am not considering modern browser concept.What happens if someone opened in other than so called modern browsers?? Will the programm runs same?? Its always better to do server side validation..
Greetings,
I'm looking for a way to launch a GWT module when a user clicks on an XML file and have the module consume the xml data. Ideally I would like to render the XML in a rich manner and would prefer to use GWT controls instead of having to lay it out by hand via xslt + javascript.
I'm supposing one way would be to point the xml to a well known xslt that creates a simple html page that forces a redirect to the gwt module but how would I transfer the xml data to said module to allow for enhanced formatting?
Another way would be to have the process that produces the xml also include the bootstrap gwt module but it would be creating multiple bootstrap instances over time and pollute the user's directory.
The use case is that a user would run this app on their local machine which outputs an XML file. If they try and view the xml file in a browser, I'd like to have the GWT module take over and present the data accordingly. I would rather they not have to go to a page and upload the data manually.
Appreciate any ideas on the matter.
TIA
If it's something that runs on the user's machine, I would recommend to ship an executable, or generate a parallel HTML file to present the data. JavaScript run from file:/// will not be able to acces the filesystem.
I am working on an application in which i write to an xml file and then send it through email and at the reciever end the receiver recives it in his/her inbox and download the file to the iphone and then open the same app on his phone and browse to this file and by clicking sync button the progra should parse the tags in the xml file.
Everything is cler but i am not sure whether we can download a file to our iphone and browse thru it our app.
Thanks, i appreciate. :)
No, I don't believe you can download a file from mail and pass it to your app to open and read. This would be for security reasons.
I think the only way to achieve this would be to not use an XML file, and instead construct a URL with parameters.
There are a few drawbacks here, though. Depending on how much data you need to pass, the url could get pretty large. You would have to take considerations to make sure that each parameter value is properly URL escaped. And you could have to write code to parse the data in the parameters.
This is how other apps pass data between apps, an example would be the iPhone's Phone app. You can make it call a number by using a tel:// URL.
You can register a URL scheme in your app and use it to pass data around.
i was trying to reverse engineer a website ("www.asklaila.com") to find out how their yahoo UI AutoComplete Widget is working. Upon finding the view source of it, i saw it is refering to a file called "/autocomplete.do", i wanted to know what does this autocomplete.do file mean and can i download and open it locally on my machine?
Hope my requisite is legitimate and ethical.
As explained by FileInfo.com, the .do extension represents a server side Java code file that runs on the server and outputs HTML to the response.
Therefore, you cannot download it and view its contents. Any requests to the file will either return the same HTML or an HTTP error if it requires parameters/form fields.