Using 'dart:io' in dartium ? Any work arounds? - dart

I am new to dart and I am trying to read data from a file and use the contents to draw something canvas. In doing so I am running into 'The built-in library 'dart:io' is not available on Dartium ' issue.
I understand Dart has limitations as Javascript in that code that is running in a browser cannot natively access the File System of the running client.
At the same time are there any tips on how to read a file and also use the contents to write it to canvas?
Thanks in advance.

What kind of application are you trying to build?
If it runs in the browser the files are usually on the server.
If it is a normal web page you can't access user files. There is a sandboxed space accessible to be used by by the code of a webpage.
If you build something like a Chrome app you have less limitations.
You definitely can't import 'dart:io' when the could should run in the browser.
The APIs available in the browser can be found in 'dart:html'.
If you want to build a Chrome app this package provides access to the extended API http://pub.dartlang.org/packages/chrome

I fixed my problem by prompting the user to choose the file. Similar approach as in
https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications but using DART.

Related

In Dart, what's the simplest way to get the bytes of a local file for a web app?

(I'm new to web stuff, I'm sorry for any botched terminology)
I want to make a Gameboy Emulator web app, and the first step in that is reading the bytes of the ROM. Eventually, the user will be able to select the ROM, but right now, I just have 'tetris.gb' in the directory along with 'index.html' and 'out.js' (the output of main.dart run through dart2js).
I've been trying to find an easy way to read the bytes of 'tetris.gb,' and the 'dart:io' library looked promising, but it's not available for browser-based applications.
In the browser you have 2 options.
Load a file from the server using an HTTP GET request.
See for example
Using dart to download a file
Load a file from the users computer using file upload functionality.
See for example File input and Dart
dart:io can only be used on the server or in console or Flutter apps, but not in code running in the browser.

Getting Twitter data in a web extension without remote scripts

I am developing a WebExtension for Firefox. In order to post my extension, it must not have any remote scripts in it.
In order to display some tweets in my extension's menu, I have used the Twitter-Post-Fetcher library, but I can't post my extension with it because the library uses remote scripts from twitter.com.
I prefer not to use the Twitter API if possible, because the requests would come from the extension's users.
No remote scripts means that if you are going execute code in the context of your extension, then the code must be included in the extension package, not hosted on some server. While there may be other ways to accomplish this (e.g. running the code in the page context, which may be acceptable, but may not), the default way to accomplish this is to: download the code that you are executing and use a copy that you include in the extension package.
This is the case for all code, including libraries such as jQuery. It is highly recommended that the code be an exact byte-by-byte copy of code that can be downloaded from a public repository, and that you indicate within your extension package the exact URL you used to obtain the code.
The reason for this is security. If downloading code at runtime was permitted, then that code could be trivially changed at any time. It would mean that having the add-on reviewed by Mozilla would be of no benefit.
Please see the Review Policies page on MDN, and all the pages linked from there, for more details.

Exporting files from a Javascript based phonegap app - options or ideas?

I'm currently writing a mobile app (hopefully iOS or android) using the jquery mobile framework and phonegap.
It'll need to export/send csv files in some way to the users, but I'd be interested to hear ideas or suggestions about the best way of doing so. If this can be done on the js side of the app that'd be ideal as it's what I'm most familiar with. A couple of options I've considered are:
Uploading the file using the google docs api
Writing the file to the file system (then export e.g. via iTunes)
I'm new to this so any suggestions gratefully received! Thanks for your help
There are a few options that you could use depending on how you want it to work.
The main options would be to
Use the File API (http://docs.phonegap.com/phonegap_file_file.md.html#File) to store files on the filesystem of the device.
Upload the file to a server using a standard XMLHttpRequest.
Write a native PhoneGap plugin on each platform that you are interested in that could connect to Google docs.
As Dave pointed out you can write files with the FILE API. I have used the file api on iOs to write custom log files and havent found any yikes so far.

How Can I Automatically Execute A Link In Internet Explorer

I am trying to create an application to print documents over the web. I have created my document, and made a web page with a meta refresh tag, along the lines of this:
<meta http-equiv="refresh" content="3;http://example.com/download.epl2" />
I specify that the document has a content-type of application/x-epl2, and I have associated .epl2 files on my computer with a program that silently sends them to the printer.
I have put the website into my trusted sites zone.
Currently Internet Explorer pops up the "Open, Save, Cancel" dialog box with no option to automatically open the file.
Is there a setting in IE6/7/8 that I can use to have IE just open the file without prompting?
EDIT
The actual content of the file will differ based on the job, but essentially it is text that follows the Eltron Programming Language.
EDIT
I have accomplished this in both Chrome and Firefox by choosing "Automatically Open Files Of This Type From Now On"
EDIT
The machines this program will be used on will effectively be kiosks that are limited to only accessing my website from their web browsers, so I'm not worried about rogue websites sending documents to my printers.
EDIT
I am using PHP to generate the documents and HTML on the server side, though I expect the solution to be language agnostic.
I would expect that not to be possible, because then you could stumble onto a site that automatically loads and prints a 5000 page document or something, which would not be good.
If you always had a secret desire to develop a custom URL protocol (I know I do), this might be a good excuse to do it. ;-)
http://msdn.microsoft.com/en-us/library/aa767914%28VS.85%29.aspx
There are 1-2 prompts when opening such a link for the first time in IE, but you can choose to automatically open them after that.
I would use javascript to make this happen.
Javascript Window Open
EDIT
Since you have control of the windows box you could use an automate script process to interact with the print window.
autoit3: ControlClick
Write a small utility program that does nothing but send the file passed to it on the command-line to the default system printer.
Then, edit the registry under HKEY_CLASSES_ROOT to associate this program with the .epl2 filetype.
I don't have time to investigate it for You, but there were lots of exploits that could be helpful. Using ie6 without certain fixes seems helpful.
Also there should be an option called "Automatic prompting for file downloads". I use Linux nowadays so I can't chceck if it helps. I found it in some docs.
I'm on a Mac at the moment, but if this is possible in IE I would imagine this page holds the answer to it (or at least hints at it) http://support.microsoft.com/kb/883255
I believe what you're looking for is a setting in Windows, not IE:
Microsoft Support: Not Prompted to Specify Download Folder for File
Try using an older version of IE. Security was looser in the older versions and since it's a non-issue, this could be the quickest solution.

Would it be possible to read clipboard on a website if the content is an image?

I have this idea for a imageshack style photo uploading service where you can paste a printscreen and then crop it in your browser. Is it possible to take the image from the clipboard into the browser?
I don't believe it is.
By default, most browsers do not allow Javascript to access the clipboard -- for instance, what if you pasted in your password to log in to a site, then someone injected a script that read the same password you use on all your sites?
Trephine is a library for browser clipboard access, and even they claim to only grab text. Moreover, I'm halfway sure that the OS decides whether to paste anything into a given application (you can't paste a screenshot into Notepad AFAIK).
So like that link in the comments above, you might have to go Java or Flash for this. It looks like AIR might let you read images from the clipboard?
No, to my knowledge it is not possible to access bitmaps from the clipbpoard. That's why at Aviary.com we built or own Firefox and Chrome extension called "Talon" to allow this kind of access: http://aviary.com/launch/talon - our Flash applications can talk via Javascript to the extension and get access to the bitmaps.

Resources