Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've pasted your code (and edited it slightly, I think there's a couple of typos), and it does serve images in chrome - at present, you would have to pass the full url of the image, eg: <code>http://localhost:1111/images/foo.png</code> </p> <p>To get a page full of images, you would either need to write an html page, eg:</p> <pre><code>&lt;html&gt;&lt;body&gt; &lt;img src="http://localhost:1111/images/foo.png"/&gt; &lt;img src="http://localhost:1111/images/bar.png"/&gt; &lt;/body&gt;&lt;/html&gt; </code></pre> <p>And there's no reason why you couldn't create that html dynamically on the server, for example, in response to a request for a file called <code>images.html</code> for example. Take a look at the <a href="http://api.dartlang.org/docs/bleeding_edge/dart_io/DirectoryLister.html" rel="nofollow"><code>DirectoryLister</code></a> class to iterate files and folders on the server side.</p> <p>Also, JJ's comment is also correct - you should also add proper headers, (although chrome seems to pretty good at interpreting stuff without the proper headers). </p> <p>For reference, here's the server side code that works fine for me (just so that I could test it... - has the 404 and options removed - it serves from the current (ie, app's own) folder).</p> <pre><code>import 'dart:io'; void startServer(String mainPath){ HttpServer server = new HttpServer(); server.listen('127.0.0.1', 1111); print("Server listening on localhost, port 1111"); server.defaultRequestHandler = (var req, var res) { final String path = req.path == '/' ? '/index.html' : req.path; final File file = new File('${mainPath}${path}'); file.exists().then((bool found) { if(found) { file.fullPath().then((String fullPath) { file.openInputStream().pipe(res.outputStream); }); } }); }; } main(){ startServer("."); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload