O'Reilly logo

Dart: Scalable Application Development by Ivo Balbaert, Sergey Akopkokhyants, Davy Mitchell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Downloading a file

This recipe shows you the simplest ways to download a file through code, first in a command-line application and then from a web application. As an example, we download the front page of the Learning Dart website from http://learningdart.org.

Getting ready

A client program (be it web or command-line) receives content, such as files or web pages, from a web server using the HTTP protocol. The dart:html and dart:io package provides us with the basic classes we need to do this, which are as follows:

  • The Uriclass class (from dart:core) has all we need to parse, encode, and decode web addresses; the method Uri.parse is often used
  • The HttpRequest class (from dart:html) has the getString method to fetch a file from a URL
  • The HttpClientclass ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required