Hi Mauricio, Werner, Michael, Thank you for your replies. I understand storing the files in file system might be an easier option, but that would be my last option. If I can make it work with the database, I've got good reasons to go with it.
I'm not trying to store an exisitng physical file into database. The file gets written dynamically. >From self._get_file(content), I get back a cStringIO.StringIO object. content = cStringIO.StringIO() fw = csv.writer(content, delimiter=',') fw.writerow(somerecord) So this is the object I get back and trying to store content.getvalue() into the database. in the Insert statement, I could see it is trying to store some binary. And it commits without any error. On Tuesday, February 26, 2013 4:43:10 PM UTC, werner wrote: > > Hi Dalia, > > On 26/02/2013 17:15, dalia wrote: > > self._get_file(content) ### This is a function which generates the > file (.xls / .doc / .pdf) in the content > > What are you getting back from _get_file? Is it in a format you can store > in the db column and then restore it to a file? > > Doing a bit of googling I found this on stackoverflow which looks > relatively simple, i.e. he suggest to use "open" with the 'rb' and 'wb' > flag for reading and writing. > > > http://stackoverflow.com/questions/3379166/writing-blob-from-sqlite-to-file-using-python > > You should be able to just use the non sqlite3 part of this, i.e. > something like: > > with open("yourfilename", "rb") as input_file: > tbl.report_file = input_file.read() > > with open("Output.bin", "wb") as output_file: > output_file.write(tbl.report_file) > > > I personally just store the file name/path and keep the data on the disk, > but there are obviously reasons to put it in a db. You might want to read > some of the other posts on stackoverflow, e.g.: > > http://stackoverflow.com/questions/3748/storing-images-in-db-yea-or-nay > > Werner > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
