I am working on drupal 7 which has content type that has a filed "file" and the file is uploaded to mysql database.
I would like to find the table where the file is stored as binary BLOB type.
Know the node ID.
Unless you have something special installed that I'm not familiar with, the files themselves aren't stored as binaries/serialized/etc in the DB. The file table (or is it the filr_managed table? I apologize, I'm on my phone and will try to answer more fully when I sit down at a computer) just stores things like the file id (fid) and the path to the file.
As I understand it, storing the files themselves, fully in the DB would lead to some pretty heavy/intense DB call times.
I'm not sure if this is a reason why you expect it to be in the DB, but if you are looking for the files to be accessible following their nodes access, you'll want to look into setting up private file storage outside of the Drupal root directory.
If you have a default configuration, you will find your files in the filesystem, in the following subdirectory of your Drupal installation :
drupal/sites/default/files
If you want to store all the file in the DB, tou can by using a hook on saving file, but it is not recommended for performance reason. Better to acces a file by URL than download it from database.
Related
net project as well as a setup project. I also have it so that during installation it asks the users to enter a file location to store their database. the plan is to have an empty .mdf file, with all the tables setup, copied into that folder and I store the folder path in a config file.
this is mainly because I am planning on having multiple separate applications that all need the ability to access the same database. I have it storing the folder path in my config file the only thing I'm having trouble with is
storing the template files I don't know if i should do this in the setup project or main project
how to copy said template files into a new folder
so far I have been unable to find a solution so any help is appreciated
Well here is what I do this in a few of my projects - something that has proven reliable enough for me over the years (which you may or may want to do as well):
I have the program itself create the database files in an initialization routine. First however, it creates the sub folders in which the database files will be stored, if they don't already exist.
To do this, the program just checks if the folder exists and if the database file exists and if they do not, it creates them on the spot:
If Directory.Exists(gSQLDatabasePathName) Then
Else
Directory.CreateDirectory(gSQLDatabasePathName)
End If
If File.Exists(gSQLiteFullDatabaseName) Then
Else
...
I also have the program do some other stuff in the initialization routine, like creating an encryption key to be used when storing / retrieving the data - but that may be more than you need (also, for full disclosure, this has some rare issues that I haven't been able to pin down).
Here too are some addition considerations:
I appreciate you have said that you want to give the user the choice of where to store their database files. However, I would suggest storing them in the standard locations
Where is the correct place to store my application specific data?
and only allowing the users to move them if the really need to (for example if the database needs to be shared over the network) as it will make the support of your app harder if every user has their data stored in different places.
I have found letting the user see in their options/settings windows where their database is stored is a good idea.
Also to encourage them to back those files /directories up.
Also to create automatic backups of several generations for the user.
Hope this helps.
I can't find answers to my question so I'm doing it. My site's database occupies 10.9 Gb of which 10.5 is the woocommerce_log folder, what can I do?? Can older logs be deleted? Is there a problem with the configuration?
Folder and Database are 2 different things.
10.5 is the woocommerce_log folder
You've mentioned folder but wrote the table name so it's confusing if you're talking about folder or database table.
however, if you are talking about the folder with the path wp-content/uploads/wc-logs then yes you can delete all the files with the extension .log
if you're talking about database table wp_woocommerce_log then generally it should be empty unless your log handler is set to DB. you can empty data from this table as well. but don't delete the table.
You also need to look in wp-config.php if you have defined a logger using constant WC_LOG_HANDLER you should use a file logging system instead of DB.
You can find more details on the WooCommerce logger on this page. https://developer.woocommerce.com/2017/01/26/improved-logging-in-woocommerce-2-7/
post_meta (in WordPress or WooCommerce) is inefficiently indexed. Suggest you add this plugin: WP Index Improvements
More discussion: http://mysql.rjweb.org/doc.php/index_cookbook_mysql#speeding_up_wp_postmeta
(Deleting unused data from any big table rarely helps as much as improving the indexes.)
I am trying to create a site where users can upload images, videos and other types of files.
I did some research and people seem to suggest that saving the files as BLOB in database is a Bad idea; instead, save the file paths in database.
My questions are, if I save the file paths in a database:
1. How do I generate the file names?
I thought about computing the MD5 value of the file name, but what if two files have the same name? Adding the username and time-stamp etc. to file name? Does it even make sense?
2. What is the best directory structure?
If a user uploads images at 12/17/2013, 12/18/2018, can I just put it in user_ABC/images/, then create time-stamped sub-directories 20131217, 20131218 etc. ? What is the best structure for all these stuff?
3. How do all these come together?
It seems like maintaining this system is such a pain, because the file system manipulation scripts are tightly coupled with the database operations(may also need the worry about database transactions? Say in one transaction I updated the database but failed to modify the file system so I need to roll back my database?).
And I think this system doesn't scale (what if my machine runs out of hard disk so I need to upload the files to a second machine? What if my contents are on a cluster?)
I think my real question is:
4. Is there any existing framework/design pattern/db that handles this problem?
What is the standard way of handling this kind of problems?
Thanks in advance for your answers.
I've actually asked this same question when I was designing a social website for food chefs. I decided to store the url of the image in a MySQL database along with recipe. If you plan on storing multiple images for one recipe, in my example, maybe having a comma separated value would work. When the recipe loaded on the page, I would fetch the image associated with that recipe onto the screen.
Since it was a hackathon and wasn't meant for production purposes, I didn't encode the file name into something unique. However, if I were developing for productional purposes, I would append the time-stamp to the media file name when storing it into the server and database/backend.
I believe what I've proposed is the best data structure of handling this scenario. Storing the image onto the server is not only faster, but it should also take less space. I have found that when converting a standard jpg file of reasonable resolution to base64 encoding, the encoded text file representation took 30% more space. There is also the time of encoding the file and decoding the file for storage and resolving when using some BLOB type of data format instead of straight up storing the file on the server.
Using some sort of backend server scripting like PHP, you'll be able to do some pretty neat stuff with the information you have available. Fetch the result from the database, and load it in from the page using HTML.
As far as I know, there isn't a standard way of fetching media from a database yet. Perhaps there will be one day.
There is not standard way to do that, it is different to the different application. The idea is you need generate a different Path+FileName for every upload, here is a way:
HashId = sha1(microsecond + random(1,1000000));
Path = /[user_id]/[HashId{0,2}]/[HashId{-2}];
FileName = HashId
Hey. I need to upload some files (images/pdf/pp) to my SQLS Database and thereafter, download it again. I'm not sure what is the best solution - store it as bytes, or store it as file (not sure if possible). I need later to databind multiple domain classes together with that file upload.
Any help would be very much apreciated,
JM
saving files in the file system or in the DB is a general question which is asked here several times.
check this: Store images(jpg,gif,png) in filesystem or DB?
I recommend to save the files in the file system and just save the path in the DB.
(if you want to work with google app-engine though you have to save the file as byte array in the DB as saving files in the file system is not possible with google app-engine)
To upload file with grails check this: http://www.grails.org/Controllers+-+File+Uploads
when i installing drupal 7 ".ht.sqlite" its create a file like this so if i want to move the site ,how can i import the database
Not sure if I get the question. If you have a file like that, it means that you have chosen sqlite as the database backend. This means that this file is the database.
If you want to move your site around, just move that file too. You can also move it to a different place, you just need to update the path to it in your sites/default/settings.php file.