jquery-filedrop icon indicating copy to clipboard operation
jquery-filedrop copied to clipboard

<XMLHttpRequest> has no method 'sendAsBinary'

Open nodesocket opened this issue 12 years ago • 15 comments
trafficstars

Getting:

Uncaught TypeError: Object #<XMLHttpRequest> has no method 'sendAsBinary' 

In Chrome 29.0.1547.76 using latest version of filedrop.js.

Seems to be breaking here:

 xhr.sendAsBinary(builder);

nodesocket avatar Sep 27 '13 04:09 nodesocket

The function sendAsBinary() seems to have been removed from Chrome.

nodesocket avatar Sep 27 '13 05:09 nodesocket

I think you can do something like:

if(!XMLHttpRequest.prototype.sendAsBinary){
  XMLHttpRequest.prototype.sendAsBinary = function(datastr) {
    function byteValue(x) {
      return x.charCodeAt(0) & 0xff;
    }
    var ords = Array.prototype.map.call(datastr, byteValue);
    var ui8a = new Uint8Array(ords);
    this.send(ui8a.buffer);
  }
}

nodesocket avatar Sep 27 '13 05:09 nodesocket

Any update on this?

nodesocket avatar Oct 05 '13 05:10 nodesocket

Even implementing:

XMLHttpRequest.prototype.sendAsBinary = function(datastr) {
    function byteValue(x) {
        return x.charCodeAt(0) & 0xff;
    }
    var ords = Array.prototype.map.call(datastr, byteValue);
    var ui8a = new Uint8Array(ords);
    this.send(ui8a.buffer);
}

Does not fix the error. Really need a solution to this. Thanks much.

nodesocket avatar Oct 12 '13 04:10 nodesocket

Just a quick drop for those who will have this issue. The solution provided http://royaltutorials.com/object-has-no-method-sendasbinary/ did the trick for me. Just replacing the "XMLHttpRequest.prototype" by "xhr". Cheers.

havenS avatar Feb 12 '14 17:02 havenS

@havenS This code is already implemented https://github.com/weixiyen/jquery-filedrop/blob/master/jquery.filedrop.js#L537 but does not seem to work. I am still getting:

 Uncaught TypeError: Object #<XMLHttpRequest> has no method 'sendAsBinary'

With Chrome (32.0.1700.107). Any ideas?

nodesocket avatar Feb 12 '14 22:02 nodesocket

The error triggered by Chrome Version 32.0.1700.107 m was on line 402. This tweak is not implemented on l.402, that did the trick for me on that line http://jsfiddle.net/MKrLa/2/ . Hope it's not luck I had.

havenS avatar Feb 13 '14 07:02 havenS

@havenS Awesome that worked. Thanks so much! Maybe we should create a PR and merge this change in?

nodesocket avatar Feb 13 '14 22:02 nodesocket

Nice ! I very glad it worked for you. I'll create the PR. Cheers.

havenS avatar Feb 14 '14 07:02 havenS

How to change the file name? Why can not I pass a file name and change it from js in php? Implement please!

Karusel avatar Dec 02 '14 04:12 Karusel

Not sure what you're trying to achieve. You need to change the filename in your php handler by passing it through the upload process ? If so, pass it to the params.

havenS avatar Dec 02 '14 06:12 havenS

I want to assign a new file name from the temporary folder and pass it to php? Sorry, i know bad English.

Karusel avatar Dec 02 '14 11:12 Karusel

In your filedrop instantiation you can set the 'data' array in which you can define any parameter that you catch later in you process: $('#yourDropZone').filedrop({ data: { params1:

havenS avatar Dec 02 '14 12:12 havenS

Thank you very much! You really helped. I spent 2 days on it. I'm really grateful to you!

Here's what happened: var fname = document.getElementById("names").value;

dropbox.filedrop({
    // The name of the $_FILES entry:
    paramname:'pic',
    data: {"nick":fname},
    params:'nick',

The file - jquery.filedrop.js

(function($){ jQuery.event.props.push("dataTransfer"); var opts = {}, default_opts = { url: '', refresh: 1000, paramname: 'userfile', params: 'nick',

Karusel avatar Dec 02 '14 12:12 Karusel

Ok if I understand well, your problem is solved ? If so, glad you can move forward on your project. For reference, here is the "how to" which led me to this library on the first time. If it can be of any help for others: http://tutorialzine.com/2011/09/html5-file-upload-jquery-php/

havenS avatar Dec 02 '14 14:12 havenS