On Jun 9, 2012, at 1:45 PM, Paul McNett wrote:

> On 6/9/12 9:49 AM, Ed Leafe wrote:
>> On Jun 9, 2012, at 11:26 AM, John Fabiani wrote:
>> 
>>>> I am having issue with the binary field type.
>>> 
>>> What type of issue?
>> 
>>      And what database?
> 
> I'm storing images to an sqlite database, I'll dig out the code. I found that 
> I
> needed different code to store to MySQL. This shouldn't be, since Dabo's 
> supposed to
> wrap the differences but that's all I had time to find out.

I can do the following just fine:

f = open('my/path/to/file.pdf', 'rb')
data = f.read() # contains binary data

outfile = open('file/to/write/to.pdf', 'wb')
outfile.write(data)


It will rewrite the data just fine.  However if I store it in a binary field in 
a bizobj and try to write from the binary field, I get a unicode error.  

f = open('my/path/to/file.pdf', 'rb')
data = f.read() # contains binary data

bizobj.setFieldVal('file', data)
bizobj.save()

data = bizobj.getFieldVal('file')
outfile = open('file/to/write/to.pdf', 'wb')
outfile.write(data)

This results in a 

UnicodeEncodeError: 'ascii' codec can't encode character: ordinal not in 
range(128)

Not sure how to proceed...  What data type does the binary database field type 
translate to?

Also, if anyone wants to know why, I have a request to link receipts (either 
email attachments, scanned pictures, or pdfs) to an expense report so that they 
can easily be found.  Storing a file location is not an option in this case.

Regards,

Nate

--- StripMime Report -- processed MIME parts ---
multipart/alternative
  text/plain (text body -- kept)
  text/html
---

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: 
http://leafe.com/archives/byMID/[email protected]

Reply via email to