Send data:image with Ajax

137 views
Skip to first unread message

spirit

unread,
May 9, 2012, 6:25:02 PM5/9/12
to greasemonkey-users
Hi, I have a problem.

I try send some img from one page (data:image/jpeg;base64) to my php
script on serwer, script write this data to txt file. But wen I send
this data to my txt file I see strange code. I wrote that this header

headers: {
"Content-Type": "application/x-www-form-urlencoded"
},

may change "+" to space and other unwanted stuff. What headers I
should use? I try palin/text but this dont work on GM.

I want only send this data to file, open file, copy this data to
browser and see image, but now nothing happend, data are not correct.

spirit

unread,
May 9, 2012, 6:43:15 PM5/9/12
to greasemonkey-users
Ok, I find solution, its simple, use encodeURIComponent.

Anthony Lieuallen

unread,
May 9, 2012, 9:50:42 PM5/9/12
to greasemon...@googlegroups.com
application/octet-stream

spirit

unread,
May 10, 2012, 3:54:30 AM5/10/12
to greasemonkey-users
Thx, I try application/octet-stream but nothing happend, data not
send (0 errors on console):

data: "answear=" + canvas.toDataURL("image/jpeg")

Only answear is send. It works as expected only when I use
"application/x-www-form-urlencoded" data are send.

But I saw another problem. I use canvas to read this data. But when I
get data, put on browser and save image I see sth strange: img looks
like the same but not the same. Canvas version is bigger, pixels are
not the same.

Any idea why? How can I save exacly the same img like the source using
JS in Greasemonkey?

Tei

unread,
May 10, 2012, 6:21:14 AM5/10/12
to greasemon...@googlegroups.com
For data that can get bigger than 64KB I have had more luck using
multipart/form-data, like if I where uploading a file in a form, than
with urlencoding. Is much harder to create, but you don't need to
encode anything, you can put the actual binary dump in the post.
--
--
ℱin del ℳensaje.
Reply all
Reply to author
Forward
0 new messages