Book Image

DART Cookbook

By : Ivo Balbaert
Book Image

DART Cookbook

By: Ivo Balbaert

Overview of this book

Table of Contents (18 chapters)
Dart Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Working with blobs


In the previous recipe, in step 1, we used a client HttpRequest object and its method getString. In this recipe, we want to download a blob (binarylargeobject) file, for example, a large image, audio, or video file. But first, you need to prepare for this if you need to do more than just download a string from a URL resource to process it on the client. You need to go through the following steps (for the code, see request_prep.dart in the project request_blob).

Getting ready

  1. Create an HttpRequest object as shown in the following code:

    import 'dart:html';
    
    void main() {
    var path = 'http://learningdart.org';
    var request = new HttpRequest();
    
  2. Open it (here, with the HTTP GET method) as shown in the following code:

    request
    ..open('GET', path)
  3. In this stage, we could also have configured its header with the setRequestHeader() method, for example, request.setRequestHeader('Content-type','application/json') when you are sending a JSON string.

  4. Define a callback function, such as requestComplete...