How to store and download a zip file in database postgres - python

I'm trying to store and then download a zip file from Postgres database. I know that this is not the best approach (i should only save the path to file) but i need to do this way, just for learning and practice.
I did a python script to store the content of the file into a bytea field but this was not my final goal. I really want to know how to save the zip file.
Any ideas? I just know python so i'm trying to this in python
Thank you guys!

If you can store the file as a bytea field then storing a zipped file is just the same.
Postgres doesn't have a concept of "file" field - you simply store the content (as you did for the original content) in bytea field.
If you're asking about zipping a file on the fly,
Take a look at zlib it's one of the common modules for such tasks.
Regards
Jony

Related

How Do I store downloaded pdf files to Mongo DB

I download the some of pdf and stored in directory. Need to insert them into mongo database with python code so how could i do these. Need to store them by making three columns (pdf_name, pdf_ganerateDate, FlagOfWork)like that.
You can use GridFS. Please check this URL.
It will help you to store any file to mongoDb and get them. In other collection you can save file metadata.

Do mysql querys in python with zip file

Im trying to do some querys on my data base, but the file is to large and is spending to much time, exists some way to upload one zip file with those querys to my table?
ps: the file have between 350Mb to 500Mb
Store the zip file somewhere else on your server and simply store the name or the file location string in your dB.
Mysql really isn't intended to store large files or better yet zip folders.
Then when you go to retrieve it just unload the file location into an <a> tag it will link to it.

save binary fields to folder?

I would like to use binary fields in openerp, but instead of save them to the database as usual, I'd like to save to file system (folder). I could use a char field to store the path but, is there a way to implement the upload and download for it?
Thanks
A module which was developed in version 6 may help you to select path for saving files instead of storing in db as binary.
check out web gallery module

OpenERP 6.1 module with upload file field

I want to create OpenERP 6.1 module with a upload binary file field as one of the fields in view.
The file will be stored in database as binary data, but before storage in database I need to parse that file, and save data as part of the other created module.
So, I don't know how to specifiy filed for upload files in a view xml file, and also how to run the uploading process. Can somebody help me about this? Some code snippets or advice how to do that.
Take a look at the way the attachments module works, particularly the binary data column. You should also look at the screen definition.

pysqlite - how to save images

I need to save an image file into sqlite database in python. I could not find a solution. How can I do it?
Thanks in advance.
write - cursor.execute('insert into File
(id, name, bin) values (?,?,?)', (id, name, sqlite3.Binary(file.read())))
read - file = cursor.execute('select bin from File where id=?', (id,)).fetchone()
if you need to return bin data in web app - return cStringIO.StringIO(file['bin'])
Do you have to store the image in the database? I would write the image to the filesystem and store its path in the DB. (You may not be able to do this, depending on your particular case.)
If you absolutely must, look here.
I am not sure if pysqlite is the same as sqlite3, which is currently default in the standard python library. But if you use sqlite3 you can store the image in a buffer object and store that in a blob field in sqlite.
Be aware of the following though:
storing images in a database is frowned upon by some, storing files and path in the database is the other possibility.
make sure you return the proper mime type
It's never a good idea to record raw types in databases. Couldn't you just save the file on the filesystem, and record the path to it in database?

Categories