Convert Raw Binary String to InputStream
Hi i want to upload a {color:#003366}JPG image file{color} in a {color:#003366}BLOB{color} field in database. At first i was using {color:#003366}AJA{color}X to send file {color:#003366}path{color} to the {color:#003366}servlet{color} creating a {color:#003366}file Object{color} from it, then {color:#003366}FileInputStream{color} from it, and finally passing it to {color:#003366}preparedstatement.setBinaryStream({color}) method. It worked great. But since{color:#003366} Firefox 3{color} stopped sending full path to database i have to use another method.
So instead of sending image path i used {color:#ff0000}nsIDOMFile{color} property of Firefox 3. It has a method {color:#003366}getAsBinary(){color} which Returns a DOMString containing the file's data in {color:#003366}raw binary{color} format. Now i access this {color:#003366}string{color} from servlet using{color:#003366} request.getParameter(){color} method which creates a {color:#003366}String containing bit code of the image file{color} (I suppose). Now how to convert this string to {color:#003366}InputStream{color} so that i can store this in BLOB field in database using prepared statement.
Right now I am using following code but it doesn't seem to work.
String image=request.getParameter("image");
try{
InitialContext context = new InitialContext();
dsource = (DataSource)context.lookup("java:comp/env/jdbc/DataSource");
con = dsource.getConnection();
ps = con.prepareStatement("SOME STATEMENT");
ByteArrayInputStream imagestream = new ByteArrayInputStream(image.getBytes());
ps.setBinaryStream(1, imagestream, imagestream.available());
int i = ps.executeUpdate();Edited by: Wonder01 on Oct 22, 2008 12:24 PM
Yeah i came across that too. But these show either iframes hack method (which really isn't ajax) or else writing large pieces of code just to generate the binary stream of the file, then manually creating multipart/form-data request were the only options until Firefox 3 introduced nsIDOMFile. See this and read first few lines (you'll understand what i mean). So i send request in the form of a parameter containing Raw Binary format of the file
Now going over to the servlet side i need to somehow accept this parameter and insert in database. First i need to know how should i receive this on servlet (By using request.getParameter() or some other method). And secondly, how to convert that to either a byte array or InputStream. I searched for it and think this might be useful. This page shows 1.) how to convert an array of raw binary data into an array of ASCII 0 and 1 characters and 2.) how to convert a String to byte array where each char of the String represents an ASCII '0' or '1'. But what i nedd is slightly different, I need to convert a String containing Raw Binary into byte array.
And thanks for the information on the file paths. It was really helpful
Similar Messages
-
Converting a binary string to a number...
Hi guys,
I'm trying to convert a binary string into a decimal integer. I'm not sure if LabVIEW has a VI that does that. I haven't found one yet. Basically, say I have the string '0101'. I want to convert that to the value '5'. Or say I'm using hex, I want '10101111' to be converted to 'AF'. So that's my dilemma. I'm hoping I'm not going to have to make my own VI. Thanks a lot!
-MikeLabVIEW has exactly what you want even if it can be hard to find it.
To convert a binary text string like "0101" to a decimal value can easily be done using the Scan Value function found under the String/Number conversion section. If you provide the format %b to it (not mentioned in the manual) you will get the decimal value of your binary string.
Also, on your front panel you can change the format of your numerical indicators by right clicking on it and selecting Format & Precision. If you have a numerical indicator you can set it do display the numbers in e.g. hexadecimal form.
However, if you want to convert a number to a hexadecimal text string you can use the Number to Hexadecimal String function also found under the String/Number conversion section.
I
attached a simple example, Conversions.vi, that shows how it works. I hope this helps. /Mikael
Attachments:
conversions.vi 14 KB -
Converting a binary string into a JPEG image in Crystal Reports 2008
Hi Gang
Iu2019m having problems converting a binary string into an image in Crystal Reports 2008
I have JPEG images stored in ECC. ECC stores the data in binary format.
Iu2019m using the ECC function module SKWF_PHIO_CONTENT_ACCESS_GET to retrieve the data. This function module has an export table, FILE_CONTENT_BINARY, which returns several lines of data. Each line contains a maximum of 1,024 characters.
When I drop the T_ FILE_CONTENT_BINARY.LINE field into my Crystal Report detail section, I wind up with a report that displays all the lines in FILE_CONTENT_BINARY table. (in my case, 19 lines are displayed.)
I created a formula to collect all the data into a single string.
whileprintingrecords;
stringvar data:= data & {SKWF_PHIO_CONTENT_ACCESS_GET.T_FILE_CONTENT_BINARY.LINE}
I added the formula to the detail section and itu2019s doing a great job collecting the data.
I then inserted a picture object in the report footer, opened the format editor, navigated to the u201Cpictureu201D tab, and inserted a formula for the u201Cgraphics locationu201D.
whileprintingrecords;
stringvar data:=data;
data
My clever idea turned out to be a disappointment . . . . my picture object is blank.
Does anyone have a solution for converting a binary string into a JPEG image?Save the JPEG in a format CR supports. Refer to the help file for the file types.
-
Mail Excel as attachment with input as binary string
Hi Experts ,
I want to design BAPI which will have one string as import parameter.
I will get binary data in this string.
Now i want to mail this binary data string as excel attachment.
Anyody knows how to convert this binary string to internal table and then send this as attachment?
Thanks & Regards ,
JIgar.check these sample programs
BCS_EXAMPLE* -
How can I convert a U32 array into binary string?
Hi
I would like to find an efficient way to convert an array of 8192 U32 into a single binary string!!!
the solution below last 550 ms on an RT target to convert 8192 U32.
The same code running on Labview (not RT) last 100ms. I don't understand why there is such a difference.
I've tryed to replace the inner loop and convert by a format string whith U32 on entry and %032b as parameter but it lasted same time.
Thanks a lotYour picture of your code didn't come through. You can't link to a picture that's on your computer, as a server on the internet cannot access your computer to display the picture for others to see. You have to upload the picture as an attachment. Then, if you want to actually display the picture in the message you have to edit your post, insert a picture, and when it asks for the URL you enter the URL of the picture. You can get the URL when viewing the message, as the link is within the message itself.
As for your question, can you just use the TypeCast function? -
Converting a Hexadecimal String to a Binary String
Hello NG,
I would like to convert an 8 Bit Hexadecimal String (example C0034000)
to it´s equivalent in binary (in this case---> 1100 0000 0000 0011...
and so on), I didn´t find any possible way to do this. I´am not
talking about the simple representation on the front pannel. Some
Postings say that this ist possible with the "Format Value" Function
adding an "%b" to the entring, but in my case it does not function.
Could someone help me, thanks in advance!> I would like to convert an 8 Bit Hexadecimal String (example C0034000)
> to it´s equivalent in binary (in this case---> 1100 0000 0000 0011...
> and so on), I didn´t find any possible way to do this. I´am not
> talking about the simple representation on the front pannel. Some
> Postings say that this ist possible with the "Format Value" Function
> adding an "%b" to the entring, but in my case it does not function.
The task here is to convert a string to a different string. The easiest
way to do this is to convert the string to a numer, then format the
number as a binary string.
On the string palette the Scan from String using %x can be used to
change a hex string into a numeric integer. The Format to String with
%b and other nodes can take a numeric i
nteger and return a string of
binary characters. These two nodes wired together with the correct
constants should do what you want.
Greg McKaskle -
How to convert binary string to ascii
Hi,
See i have a string like this,
String str = "10011100110001011001110011000101";
Now i want to find exact ascii value of the binary string.
Thanks in advance.First want to convert these bits to corresponding
characters and then have to find ascii of the same.... corresponding to what? I think converting these "bits" to the corresponding chars is the whole story. But what about the original format?
Guessing mode on ... does this help?
String input = "...";
StringBuffer result = new StringBuffer();
for (int i = 0;i < input.length();i += 8) {
result.append((char) Integer.parseInt(input.substring(i, i + 8), 2));
System.out.println(result); -
Ok. Short and sweet first post here. Thanks in advance for any assistance.
I've done this same process on jpegs many times without issue. This time I forgot where I was in my workflow and tried a batch rename on my raw files.
I selected all raw files in a folder, went to tools --> batch rename and entered my file naming sequence as I wanted it to read. Hit enter and watched the file names change correctly BUT the actual files were converted to "binary documents" and I can't figure out how to get them back to raw. My thumbs are gone. If I click on one of the files, the exec file tries to load in terminal.
What happened to my raw files? There are 255 images here from a wedding that I would rather not edit all over again. Please help!
Mac OSX 10.5.7
Bridge CS3 2.1.1.9Ok. The files don't read any particular extension as seen in my previous attachment. F2 brightens my monitor. It is not associated with any other shortcut. Right click --> rename (not batch) brings the thumbnail back but without the edits. All I did in the beginning was batch rename a folder full of raw images plus 3 psd files. Nothing else. You can see that "new extension" is selected in the top field of the batch rename window. is this the mistake and how can I recover my edits if it is.
There are 253 edited images in this folder. Manual renaming will take ages. Editing all of them again is also making me ill. I was prepping the files for client submission which is due today when this happened. -
Convert signal to binary string
Hi all : I get waveform signal (square signal) from scope .. and I want to convert this signal to binary string … Can I do that in labview 8.5
thankselyan a écrit:
Hi all : I get waveform signal (square signal) from scope .. and I want to convert this signal to binary string …
Hello,
Is that what you want to do ?
http://img514.imageshack.us/my.php?image=scopetostringls7.jpg
sage Edité par tinnitus le 12-31-2008 05:35 AM
Message Edité par tinnitus le 12-31-2008 05:36 AM
CLAD / Labview 2011, Win Xp
Mission d'une semaine- à plusieurs mois laissez moi un MP...
RP et Midi-pyrénées .Km+++ si possibilité de télétravail
Kudos always accepted / Les petits clicks jaunes sont toujours appréciés
Don't forget to valid a good answer / pensez à valider une réponse correcte -
Decoding binary strings from 10 bit A/D converter
Hi all,
I'm working on a project for school that requires me to take data from an A/D converter ( the A/D is on a Motorola HCS12 microcontroller) and send it to a PC running LABVIEW to decode the binary string into a numerical value. The value will be plugged into an equation. I planned on using the serial port on the PC for the comm port. Are there any examples available or any advice to get me started in the right direction.
While I have programmed with LABVIEW in the past (academically) I am not proficient. And this type of interfacing I have not done before, only GPIB.
The A/D is 10 bit. How quick LABVIEW decodes the binary string and returns a value is not important.
If any more info. is needed let me know.Be confident. That should not be a big problem, since you'll get the help of the LV community
The most difficult part will be to establish the communication with your micro-controler. But if you can do that with Windows hyperterminal, then you are nearly done ! There are examples of serial com in the examples shipped with LV.
The string to decimal conversion will not be a problem, whatever the string format : the conversion is done using functions also shipped with LV.
Hope to see you soon with more specific questions.
Chilly Charly (aka CC)
E-List Master - Kudos glutton - Press the yellow button on the left... -
Binary String convertion.
I've question on binary string convert to array of text/number.
I'm tried to use GPIB read to retrieve a trace of Maxhold data (n number
of frequency) from ESMI Spectrum Analyzer. however, those data always
come out to binary string. So is there anyway i can convert Binary
string --> ascii (in my case, array of number/text), or to retrieve
readable data from the Spectrum Analyzer.
Very appreciate for help.
Jacky WongI've question on binary string convert to array of text/number.
I'm tried to use GPIB read to retrieve a trace of Maxhold data (n number
of frequency) from ESMI Spectrum Analyzer. however, those data always
come out to binary string. So is there anyway i can convert Binary
string --> ascii (in my case, array of number/text), or to retrieve
readable data from the Spectrum Analyzer.
Very appreciate for help.
Jacky Wong -
Converting string into inputstream and outputstream Jsch (ssh connection)
hi,
I'm not really sure if this is the place where i should ask this, but if it is so then tell me!
So my problem is that everything works just fine with input output streams like in this code, but i need to change this input stream into string messadge(Which would work!!)
The main problem is not that i can't change string to inputstream, but that when i use inputstream every commands works, and when i try to do the same with sting>inputstream this doesn't work...
unfortunatelly newgrp server; or newgrp doesn't rerally work just frezzes :/
anyway i solved the initial problem, because Jsch have two (probably more methods of sending info to unix server, but because there is no documentation htere no way to know :D)
methods of sending info to server : exec and shell , the exec sends one command and only works with commands like date;ls... now the shell can easily send any type of command including newgrp server1, and everything works :)
so we connect to the server(passw,user,host) then excecute commands, this code works perfectle but the commented code// doesn't work :
JSch jsch=new JSch();
String host=null;
String user="me1234";
host="super.server.co.uk";
String passw="12345";
Session session=jsch.getSession(user, host, 22);
session.setPassword(passw);
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
Channel channel=session.openChannel("shell"); //the power of shell, if i use exec doesn't excecute newgrp...
//String command = "newgrp xxxx;"; //this doesn't work ...
//InputStream is = new ByteArrayInputStream(command.getBytes("UTF-8"));
//channel.setInputStream(is);
//then somehow printout the response from server...
channel.setInputStream(System.in); // well instead of this I'd prefer channel.send(command);
channel.setOutputStream(System.out);
channel.connect();
Edited by: 842778 on 14-Mar-2011 01:42You seem to be leaving out the newlines.
-
How to convert raw data to original data
Hi,
I'm using db10g.
I have stored the blob of a word doc into the database using dbms_lob package.
Now during retrieval, i'm getting the raw data using the code
dbms_lob.read( l_lob, l_amt, l_off, l_raw );
l_raw is of type raw.
I want to convert the raw data to original string.
Please Help
ThanksDivya wrote:
I think I have clearly told that i have blobs of different files in my database.
The files are of different type, I have blob of pdf,doc,html,xml,gif etc...
and in the procedure i have posted(get_file_contents), it is a database procedure and i'm calling it from the forms.
So i'm passing the file_name and file_id to the procedure(file_name and file_id are the columns in the table.
Table 'Blob_Details' have 4 columns file_id,file_name,file_type,theblob) and a varchar variable final_data.
final_data varchar(32000)
and in the procedure i'm taking the blob from database, reading it using dbms_lob.read in a loop and casting it to varchar and storing the contents in the variable final_data.
So coming out of the loop, the variable final_data will have the contents of the given file.BLOB data (such as word or excel documents and PDFs containing images etc.) are Binary data, not Character data. Converting that raw binary data to VARCHAR will cause issues.
If you have loaded a binary file and stored it on the database as a BLOB (Binary data) and you now want to create the original file from that BLOB, you will simply need to read the BLOB data from the database into BLOB variable and process it in chunks, using UTL_FILE to write out, in Binary mode, that data to a file with the appropriate filename. The actual process is quite simple...
As sys user:
CREATE OR REPLACE DIRECTORY MY_FILES AS 'c:\myfiles';
GRANT READ,WRITE ON DIRECTORY MY_FILES TO myuser;As myuser:
DECLARE
-- Data Variables
v_blob BLOB;
v_data_length NUMBER;
-- Loop Control Variables
v_offset NUMBER := 1;
v_chunk CONSTANT NUMBER := 32767; -- maximum chunk size
-- UTL_FILE variables
fh UTL_FILE.file_type;
BEGIN
v_blob := ... populate the blob variable here
v_data_length := DBMS_LOB.getlength (v_blob);
-- Open the file
fh := UTL_FILE.fopen ('MY_FILES', 'myfile.dat', 'wb', v_chunk);
LOOP
-- Exit when our file offset is bigger than our file
EXIT WHEN v_offset > v_data_length;
-- Write the output chunk by chunk
UTL_FILE.put_raw (fh, DBMS_LOB.SUBSTR (v_blob, v_chunk, v_offset), TRUE);
-- Increment the offset by the amount written
v_offset := v_offset + v_chunk;
END LOOP;
-- Close the file
UTL_FILE.fclose (fh);
END; -
Need to convert a binary value into decimal
Hi i need to convert a binary value which i would be getting as a string object to a decimal value......need code for the same
Check Integer.parseInt
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Integer.html#parseInt(java.lang.String,%20int) -
Conversion of Decimal to Binary String
Hello Labview People:
I'm rather new to Labview, so this may be a simple-minded question . . .
I would like to take a numeric control and have the decimal input
converted to a binary string of 8 bits. So, for example, if I were to
put in the number '127', I would get out (on an indicator) the string:
01111111
The number '128' would show on the indicator as:
10000000
It seems to me that this should be simple, but somehow I cannot figure
out how to do it. Must an array be built bit by bit to accomplish this?
(I'm afraid I don't yet know how to build arrays.)
Thanks in advance for any help you provide!
Sent via Deja.com http://www.deja.com/
Before you buy.Or, you can go under the numeric function, and look for conversions, get
decimal to byte array conversion.
Then what you need to do is to get an array selection vi, and index to zero.
I don't remember the exact name of the VI's because I don't have LabView
here with me.
Perhaps this complicates things
Steven
"Timo Miettunen" wrote in message
news:[email protected]..
> use format into string VI from string palette
>
> format string should be "%08b" for 8 bits, "%016b" for 16 bits etc.
>
> timo
>
> Ananda Dave wrote:
> >
> > Hello Labview People:
> >
> > I'm rather new to Labview, so this may be a simple-minded question . . .
> >
> > I would like to take a numeric control and have the decimal input
> >
converted to a binary string of 8 bits. So, for example, if I were to
> > put in the number '127', I would get out (on an indicator) the string:
> >
> > 01111111
> >
> > The number '128' would show on the indicator as:
> >
> > 10000000
> >
> > It seems to me that this should be simple, but somehow I cannot figure
> > out how to do it. Must an array be built bit by bit to accomplish this?
> > (I'm afraid I don't yet know how to build arrays.)
> >
> > Thanks in advance for any help you provide!
> >
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
>
> --
> -------------------------------------------------
> Timo Miettunen
>
> Fincitec Oy Production Department
> e-mail: [email protected]
> Address:
> Lumikontie 2 Tel: +358-16-2151245
> PO BOX 11 Fax: +358-16-221561
> FIN-94600 KEMI Finland
> -------------------------------------------------
Maybe you are looking for
-
HT4864 Can i use my old email address on ICloud?
Can i use my old email address on ICloud?
-
Hard-Power off caused BIOS to stop working (NOT because of BIOS Flash)
I was trying to boot up a live CD on my Toshiba Satellite P305D-S8900. The F12 key to pull up the boot menu didn't work, and it started to boot to Windows. I let it get past the "Starting Windows" Orab (running Windows 7), and hard-powered it off w
-
I recently bought an i- Pod Touch. Whenever I try to sync I get a message
i recently bought an i-pod touch. I have loaded i-tunes be whenever I want to sync. or when I switch the computer off i get the message " i-tunes-exe Application error. The instruction at "0x00000008" reference memory at 0x00000008". The memory cou
-
Bug: Copying and pasting a htmlText ignores embed font???
- Adobe Flash Pro CS4 - Reproducible in Flash player 9 and 10 There seems to be a bug when copying a string value from a "htmlText" textfield and then pasting it in a standard "text" textField, and then adding that text back into the htmlText textFie
-
Timeline has over 2 minutes of black added to projects?
Hi, Ive been a FCP user for 5 year and all went well but a few months ago i started getting this weird thing where when i would export out my videos would have 1-5 minutes of black at the end of them. I have un and re-installed the program, i have tr