WebFund 2016W Lecture 17

From Soma-notes
Revision as of 17:58, 15 March 2016 by Soma (talk | contribs) (Created page with "==Video== The video from the lecture given on March 15, 2016 [http://homeostasis.scs.carleton.ca/~soma/webfund-2016w/lectures/comp2406-2016w-lec17-15Mar2016.mp4 is now availa...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Video

The video from the lecture given on March 15, 2016 is now available.

Notes

Instructor comments

In class I had trouble with downloading the file. Everything worked except that the downloaded file became [Object object].

The problematic line was this, in downloadFile()

 response = allFiles[i].buffer.toString('utf8');

This line should work because when we stored the file in uploadText() it did. But in between (perhaps when stored as a session property) it was changed.

Before, we had:

 { '0': 123,
   '1': 10,
   '2': 32,
   '3': 32,
   ...
 }

But now this got changed into:

 { type: 'Buffer',
   data: 
    [ 123,
      10,
      32,
      32,
      ...
    ]
 }

The former is of type Buffer (as reported by Buffer.isBuffer()), the latter is not.

While this is strange behavior, the fix is easy:

 response = Buffer(allFiles[i].buffer.data).toString('utf8');

This is definitely a bug in node or express. If anyone wants to try isolating this bug and reporting it, let me know!


Code

upload-demo with working download button