Pregunta

I need an example for using the DirectoryEntry and DirectoryReader classes in Dart:HTML. The following code read an image file from img directory and load it as an image element in the browser.

import 'dart:html';

void main() {
  ImageElement image = new ImageElement(src: 'img/car.jpg');
  querySelector('body').append(image);
}

Here is the structure of my webapp directory:

webapp directory's structure

I need to dynamically list and use the content of img directory.

¿Fue útil?

Solución

'img/car.jpg' is a file on the server which the browser requests from your server when you assign the path to an <img> element.
DirectoryEntry and DirectoryReader work on the client only.

What you need is that the server provides an API (e.g. JSON) that lets you request a list of files/directories from your server (e.g. of your img directory). If your server has directory listing enabled you could alternatively send a simple HTTP request with /img as URL and parse the response.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top