REST API Media File Post

I'm trying to upload files to media gallery.. using just the rest calls. I keep getting an error: Only a posted file, file URL, or file upload context is valid, but not more than one.

This rest call is in a method called model.createMediaPost(args) but this is just the important part which is the rest call

                url: _baseUrl + _mediaRestApi,
                callback: callback ? callback : _callbackname,
                data: { 
                   "mediagalleryid": _mediagalleryId,
                   "Name": _name,
                   "FileData": _filedata,
                   "Tags": _tags,
                .error(function (err) {
          "error with media  file rest call:", err);
                    _error = err;
                }).success(function (r) {

                    if (typeof callback !== 'undefined' && typeof callback === 'function') {

                    _results = r;

The byte[] maybe okay... but here is the code that calls the above method "createMediaPost":

var filedata = [];
var reader = new FileReader();

	reader.onloadend = function (evt){
		if ( == FileReader.DONE) {
			var arrayBuffer =,
				array = new Uint8Array(arrayBuffer);
			for (var i = 0; i < array.length; i++) {
		  model.createMediaPost(mediagalleryId, name, description, filename, filedata, tags, function(result){"media gallery posted");;