From c91b22812fc57f035a8fa2df38ebab929c12011b Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sun, 22 Jan 2012 16:45:34 +0100 Subject: [PATCH] Finally fix file upload on Firefox. --- 4chan_x.user.js | 11 ++++++++--- script.coffee | 9 +++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 4b50b815e..2c8f0c579 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1596,7 +1596,7 @@ post.upfile = file; return qr.message.send(post); }; - reader.readAsArrayBuffer(reply.file); + reader.readAsBinaryString(reply.file); return; } return qr.message.send(post); @@ -1643,7 +1643,7 @@ return postMessage(data, '*'); }, receive: function(data) { - var bb, form, name, url, val, _ref; + var bb, form, i, l, name, ui8a, url, val, _ref; if (data.abort) { if ((_ref = qr.ajax) != null) _ref.abort(); return; @@ -1653,8 +1653,13 @@ url = "http://sys.4chan.org/" + data.board + "/post?" + (Date.now()); delete data.board; if (engine === 'gecko' && data.upfile) { + l = data.upfile.buffer.length; + ui8a = new Uint8Array(l); + for (i = 0; 0 <= l ? i < l : i > l; 0 <= l ? i++ : i--) { + ui8a[i] = data.upfile.buffer.charCodeAt(i); + } bb = new MozBlobBuilder(); - bb.append(data.upfile.buffer); + bb.append(ui8a.buffer); data.upfile = bb.getBlob(data.upfile.type); } form = new FormData(); diff --git a/script.coffee b/script.coffee index 8f02da31e..ec5a0c85c 100644 --- a/script.coffee +++ b/script.coffee @@ -1216,7 +1216,7 @@ qr = file.type = reply.file.type post.upfile = file qr.message.send post - reader.readAsArrayBuffer reply.file + reader.readAsBinaryString reply.file return qr.message.send post @@ -1274,8 +1274,13 @@ qr = url = "http://sys.4chan.org/#{data.board}/post?#{Date.now()}" delete data.board if engine is 'gecko' and data.upfile + # binary string to ArrayBuffer code from Aeosynth's 4chan X + l = data.upfile.buffer.length + ui8a = new Uint8Array l + for i in [0...l] + ui8a[i] = data.upfile.buffer.charCodeAt i bb = new MozBlobBuilder() - bb.append data.upfile.buffer + bb.append ui8a.buffer data.upfile = bb.getBlob data.upfile.type form = new FormData() for name, val of data