Re: AJAX Request: receive base64 encoded image in responseText

501 views
Skip to first unread message

Victor

unread,
Aug 13, 2012, 8:00:46 AM8/13/12
to prototype-s...@googlegroups.com
I deliver a URL to my controller service via prototype ajax. This one is fetching the image and returns
the image base64_encoded.

While observing the response I noticed just an empty result.

How are you observing the response? Use network sniffer and/or Network pane from Web Developer Tools in Chrome (Shift+Ctrl+I). Check content and type of the response ('Content-Type' header).

mabei

unread,
Aug 14, 2012, 3:24:51 AM8/14/12
to prototype-s...@googlegroups.com
Dear Victor,

thanks for your reply. I checked the response header and it's "
Content-Type:
text/html; charset=UTF-8".
Unfortunately I couldn't check the response because it's empty. Printing the return-part in my controller
I got the correct base64-encoded string. I checked prototype api docs and it says, the response is going to be eval'd
before it shows up in browser.

So what to do? Simply change the response content type? Is there any base64-Type?

regards
mabei

mabei

unread,
Aug 14, 2012, 5:08:16 AM8/14/12
to prototype-s...@googlegroups.com
Additional info: when I print out the response to console I only receive:

<img src='data:image/jpeg;base64,' width='262'/>

So my base64-encoded string is cutted out. When calling my reloadurl directly in the browser the image shows up correctly.
Any further suggestions to this?
 
regards
mabei

Victor

unread,
Aug 15, 2012, 5:47:25 AM8/15/12
to prototype-s...@googlegroups.com
I checked the response header and it's "
Content-Type:
text/html; charset=UTF-8".
Unfortunately I couldn't check the response because it's empty.

Is response empty in network sniffer/web inspector? Or in javascript code?
 
Printing the return-part in my controller I got the correct base64-encoded string.

You should check if it is actually written to HTTP response (maybe response is already flushed).
 
I checked prototype api docs and it says, the response is going to be eval'd
before it shows up in browser.

So what to do? Simply change the response content type? Is there any base64-Type?

How are you processing response? Please show your code (here or in jsfiddle.net) or give a link to test site. Ajax.Response#responseText should be filled from XMLHttpRequest#responseText no matter which Content-Type is in response.

mabei

unread,
Aug 15, 2012, 7:54:38 AM8/15/12
to prototype-s...@googlegroups.com
Dear Victor,


Am Mittwoch, 15. August 2012 11:47:25 UTC+2 schrieb Victor:
I checked the response header and it's "
Content-Type:
text/html; charset=UTF-8".
Unfortunately I couldn't check the response because it's empty.

Is response empty in network sniffer/web inspector? Or in javascript code?
 The response is already empty in web inspector.
 
Printing the return-part in my controller I got the correct base64-encoded string.

You should check if it is actually written to HTTP response (maybe response is already flushed).
If I return some HTML in addition to my base64 string the HTML arrives in response.
 
I checked prototype api docs and it says, the response is going to be eval'd
before it shows up in browser.

So what to do? Simply change the response content type? Is there any base64-Type?

How are you processing response? Please show your code (here or in jsfiddle.net) or give a link to test site. Ajax.Response#responseText should be filled from XMLHttpRequest#responseText no matter which Content-Type is in response.
You can find the js code here: http://pastebin.com/Y9SFVxKq

Victor

unread,
Aug 16, 2012, 5:53:22 AM8/16/12
to prototype-s...@googlegroups.com
Is response empty in network sniffer/web inspector? Or in javascript code?
 The response is already empty in web inspector.

Very bad
 
You should check if it is actually written to HTTP response (maybe response is already flushed).
If I return some HTML in addition to my base64 string the HTML arrives in response.
 
There is some problem in your server code. You should see returned base64 string in response in Web Inspector/network sniffer.

the js code here: http://pastebin.com/Y9SFVxKq 

http://pastebin.com/CeREQhtd - cleaned up version, try this, you had extra space between parameter name and value in your code, also element manipulations were ineffective. 
Reply all
Reply to author
Forward
0 new messages