Skip to content

Instantly share code, notes, and snippets.

Last active Feb 2, 2017
What would you like to do?
Example RxJS file dnd upload
var mouseDropS = $('#drop').onAsObservable('drop')
var uploadsS = mouseDropS.flatMap(function(e) {
var fileList = e.originalEvent.dataTransfer.files
var files = range(fileList.length).map(function(i) { return fileList[i] })
return Rx.Observable.fromArray( {
var subject = new Rx.ReplaySubject(1)
var reader = new FileReader()
reader.onload = function(e) {
var fd = new FormData()
fd.append('contentType', file.type)
var ajaxS = $.ajaxAsObservable({
type: 'POST',
url: '/upload',
data: fd,
processData: false,
contentType: false
return subject.asObservable()
uploadsS.subscribe(function (s) { s.subscribe(log) })
Copy link

haf commented Nov 8, 2015

I like this, but you probably don't need to first load the file; if you don't, then the browser just sends the binary file instead of the base64-encoded one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment