Re: Base64
Re: Base64
- Subject: Re: Base64
- From: email@hidden
- Date: Wed, 3 Jul 2002 14:24:18 -0400
In a message dated 7/2/02 2:35:04 PM,
Michael Schmidt Hamburg asked,
>
Hi, all! I would like to get the base64-encoded content of
>
a file (JPEG or GIF) to write it into a SQL-Database. I
>
tried Tanakas OSAX, but my MSSQL contains special
>
characters then and after decoding the result is not the
>
same as the source.
base64 would be a good encoding, and Tanaka's OSAX 2.0.1 has both encode and
decode calls. I don't know why it would produce special characters, as the
whole idea of base64 encoding is to convert an 8-bit character six bits at a
time into characters drawn from a very safe subset of 64 characters: 26 upper
case and 26 lower case letters, 10 digits, and three very safe punctuation
characters (+, /, and =). (I know that's 65 characters. "=" is used to pad out
the end of strings, if the 8-bit characters and 6-bit chunking don't come out
even.)
If you are GETTING weird characters from encoding, check that you are calling
the Encode and not the Decode handler. (But if you feed Decode something that
contains characters outside the base-64 set, you'll get a Parameter Error.)
Also make sure you are calling Encode with a plain string data type. If you
call it with a list or record, when you decode you'll get a text representation
of the structured data, like this:
{65,66,67,68,69}
MT Encode base64 result
MT Decode base64 result
-->Result: "----XlistlongAlongBlongClongDlongE"
(Actually, the X is a box character, probably ASCII code 5.)
You might think you could call it with an alias (since Decode can decode to a
file, shouldn't Encode be able to encode a file?) but it won't work that way.
If you encode an alias, you get an encoding of the alias information: file name,
path, disk, creator code, date, etc. Same thing for file and file specification
types.
Are you reading the data in as a string properly? Check the length of the
string you get to make sure you are getting the whole file.
If you can't get base64 to work, you could use some other less efficient
encoding, like the hex format Akua Sweets provides, or one of the coercisions
from Sigma's Coercions. In that case, I'd recommend using "as data string",
which can encode almost any AppleScript data structure into a text stream. You
can then get back the original data type by coercing the text stream "as
original type".
Or, you might look at what the database offers for "BLOBS" (Binary Large
Objects). But then you'll have to encode BLOB into whatever format SQL wants.
--
Scott Norton Phone: +1-703-299-1656
DTI Associates, Inc. Fax: +1-703-706-0476
2920 South Glebe Road Internet: email@hidden
Arlington, VA 22206-2768 or email@hidden
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.