473,881 Members | 1,612 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Binary Get w/ XHTMLHttpreques t

Hi all...
I need to load an image, access it's content and render it.

So, tried:

<script type="text/javascript">

xmlHttp = new XMLHttpRequest( );
xmlHttp.open("G ET", "http://127.0.0.1/image.jpg", false);
xmlHttp.send(nu ll);
imgbin = xmlHttp.respons eText;

alert(imgbin.ch arAt(10)); //just for testing the access
//returns an empty box
</script>

<img src="javascript :imgbin">
Since the javascript code works for html files, i think the problem is
the binary content.

The <img src...> failed too.

Any Hints???

Jul 23 '05 #1
17 5677


jo*********@yah oo.com wrote:

I need to load an image, access it's content and render it.
How about
var img = document.create Element('img');
img.src = 'whatever.gif';
img.alt = 'whatever';
document.body.a ppendChild(img) ;
if you need to do it dynamically.
So, tried:

<script type="text/javascript">

xmlHttp = new XMLHttpRequest( );
xmlHttp.open("G ET", "http://127.0.0.1/image.jpg", false);
xmlHttp.send(nu ll);
imgbin = xmlHttp.respons eText;


It is called responseText for a reason.
I think MSXML also has a responseBody property but I don't think
JavaScript can do much with that but passing it on to another method
that can take such an array of bytes as JavaScript itself doesn't know
bytes.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
<jo*********@ya hoo.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Hi all...
I need to load an image, access it's content and render it.

So, tried:

<script type="text/javascript">

xmlHttp = new XMLHttpRequest( );
xmlHttp.open("G ET", "http://127.0.0.1/image.jpg", false);
xmlHttp.send(nu ll);
imgbin = xmlHttp.respons eText;

alert(imgbin.ch arAt(10)); //just for testing the access
//returns an empty box
</script>

<img src="javascript :imgbin">
Since the javascript code works for html files, i think the problem is
the binary content.

The <img src...> failed too.

Any Hints???


Why not just:

<img src="http://127.0.0.1/image.jpg">
Jul 23 '05 #3
Because i need to access it's content first.

Jul 23 '05 #4
Some texts on internet says it is possible but don't show an example,
or a code like mine.

Jul 23 '05 #5


jo*********@yah oo.com wrote:
Some texts on internet says it is possible


I don't think that the JavaScript string type can deal with binary image
data, if I try the following with Mozilla (where kiboInside.gif is a GIF
image Mozilla can render without problems when directly referenced in
the source attribute of an <img> element) Mozilla fails to render the
dynamically created image correctly, it has the right dimensions but
nothing more:

var httpRequest;
if (typeof XMLHttpRequest != 'undefined') {
httpRequest = new XMLHttpRequest( );
httpRequest.ope n('GET', 'kiboInside.gif ', true);
httpRequest.onr eadystatechange = function () {
if (httpRequest.re adyState == 4) {
var status = httpRequest.sta tus + ' ' + httpRequest.sta tusText +
'\r\n' +
'length: ' + httpRequest.res ponseText.lengt h + '\r\n' +
httpRequest.res ponseText;
alert(status);
window.imgSourc e = httpRequest.res ponseText;
var img = document.create Element('img');
img.src = 'javascript:img Source';
document.body.a ppendChild(img) ;
}
};
httpRequest.sen d(null);
}

And the length of the string responseText displayed is not the number of
bytes that Windows shows me for that image file.

And IE/Win for instance doesn't support
<img src="javascript :...">
at all, otherwise the pnglets from
<http://www.elf.org/pnglets/>
would work with IE.


--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #6
<jo*********@ya hoo.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
Because i need to access it's content first.


Why? What do you want to do with binary data?
Jul 23 '05 #7
I need to check if the image sent was the one that i want.

//algorithm

if(image.data == "data i want"){
show("Yes it is the rigth image");
}
else{
show("Wrong image");
}

Jul 23 '05 #8
<jo*********@ya hoo.com> wrote in message
news:11******** ************@z1 4g2000cwz.googl egroups.com...
I need to check if the image sent was the one that i want.

//algorithm

if(image.data == "data i want"){
show("Yes it is the rigth image");
}
else{
show("Wrong image");
}


I still don't understand -- but I don't have it as I'm just curious.

1) Wouldn't "image.data " contain binary data?

2) Wouldn't your script have to contain binary data as well for
comparison?
Jul 23 '05 #9
1) Yes.

2) Supose we have files on Gif, jpg and bmp. How could i check this
files without opening the binary?
I would have to convert it to RGB for example and then check
'imgae[ i ] [ j ]'.
It's a lot of work and would collapses my system.

Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
15295
by: yaipa | last post by:
What would be the common sense way of finding a binary pattern in a ..bin file, say some 200 bytes, and replacing it with an updated pattern of the same length at the same offset? Also, the pattern can occur on any byte boundary in the file, so chunking through the code at 16 bytes a frame maybe a problem. The file itself isn't so large, maybe 32 kbytes is all and the need for speed is not so great, but the need for accuracy in the...
20
7582
by: Christian Stigen Larsen | last post by:
A signed int reserves one bit to signify whether a number is positive or negative. In light of this, a colleague asked me whether there existed an int in C++ that was -0, a zero with the negative bit set. I was intrigued by this, so I tried the following code: #include <stdio.h> int main(int, char**) { int a(-0); printf("a=%d\n", a);
3
3501
by: Tron Thomas | last post by:
What does binary mode for an ofstream object do anyway? Despite which mode the stream uses, operator << writes numeric value as their ASCII representation. I read on the Internet that it is possible to change the behavior of operator << so it will stream numeric values as their actual values when an ofstream is in binary mode. I did not, however, find any information on how this can be accomplished. What is involved in getting this...
103
48816
by: Steven T. Hatton | last post by:
§27.4.2.1.4 Type ios_base::openmode Says this about the std::ios::binary openmode flag: *binary*: perform input and output in binary mode (as opposed to text mode) And that is basically _all_ it says about it. What the heck does the binary flag mean? -- If our hypothesis is about anything and not about some one or more particular things, then our deductions constitute mathematics. Thus mathematics may be defined as the subject in...
2
2543
by: Lisa Pearlson | last post by:
Hi, My php application (on Apache/Linux) needs to do the following: The PHP script receives a request from a client (binary), asking for certain records of data. My PHP script loops through all records and sends each of them ONE BY ONE. After each record that my server script sends, it waits for the client to confirm proper reception with an ACK (binary digit). When there are no more records, my server script sends the client a binary
9
6531
by: Ching-Lung | last post by:
Hi all, I try to create a tool to check the delta (diff) of 2 binaries and create the delta binary. I use binary formatter (serialization) to create the delta binary. It works fine but the delta binary is pretty huge in size. I have 1 byte file and 2 bytes file, the delta should be 1 byte but somehow it turns out to be 249 bytes using binary formatter. I guess serialization has some other things added to the delta file.
3
2130
by: John R. Delaney | last post by:
I am running in debugging mode after a clean C++ compilation under .NET 2003. In a BIG loop (controlled many levels up in the call stack), I open a file with fopen using the "a" option. Then I write 23 doubles to it with fwrite, one call for each double. Then I close the file using fclose. After three times around the loop in the debugger, I stop the program (using "Stop debugging"). That is writing 552 bytes. The resulting file's properties...
10
22793
by: rory | last post by:
I can't seem to append a string to the end of a binary file. I'm using the following code: fstream outFile("test.exe", ios::in | ios::out | ios::binary | ios::ate | ios::app) outFile.write("teststring", 10); outFile.close(); If I leave out the ios::ate and ios::app modes my string is written to the start of the file as I'd expect but I want to write the data to
16
4509
by: Erwin Moller | last post by:
Why is a binary file executable? Is any binary file executable? Is only binary file executable? Are all executable files binary? What is the connection between the attribute of binary and that of executable?
0
9927
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10814
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9552
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7109
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5977
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4597
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4196
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3223
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.