WinForms and Access Database Attachments - winforms

If I have a PDF file saved into an attachment field in an Access database, is there anyway I could get that attachment from the database and view it in the WinForm? Or the WinForm WebBrowser maybe?
Or am I just better off sticking to a field in the database that tells me the file path of said file so I can navigate my WebBrowser to that?

I've been working with Access since long before Access 2007 introduced the Attachments field type, so I have a history of shying away from imbedding images and documents in the database. (They tended to bloat the database quite significantly, and the OLE "wrappers" added to the files were a real nuisance when trying to extract the files via code.)
Access 2007+ makes this quite a bit simpler with the Attachments field because DAO has been updated to support .SaveToFile and .LoadFromFile on Attachments. Also, attachments are (apparently) compressed when saved to the database, which should help with the bloat problem.
So, I'd say that the choice is really up to you, because if you want to view (or preview, or open) the PDF attachment in your WinForm then you'll probably wind up using Microsoft.Office.Interop.Access.Dao to save the attachment as a temporary file anyway. Therefore, whatever mechanism you use to preview/view/open the attachment will be working on a file; it will either be
a temporary file extracted from the database, or
a persistent file in a filesystem that you reference from a pathname or URL in the database.

To read the file from the database you would need to read the bytes from the database and write them to a new pdf file, then point your viewer to that file. To view a pdf directly on the WinForm you would need a 3rd party control. If you have a plugin where you can view pdfs in your browser, the WinForm WebBrowser will work.
Storing just the path in the database leads to less hassle from a coding standpoint, because you are going to have to point your viewer to a file anyway. Also is theres an issue with the database, there is a higher chance all the attachments will be lost. On the flipside, if just the paths are stored you need to make sure those paths are always accessible.
I would recommend storing them outside of the database for the above reasons, especially if this is a larger database.

Related

Picture on phpmyadmin

I would like to put photos in my phpmyadmin database but I can't find the solution that allows me to do so. I made an image array with a varchar but I can't find the path that allows to put an image. I thank you in advance for helping a young beginner ❤️
The best solution is to store the image as a file on disk and put the path to the file in the database (as a varchar or some other text type), then your application references the file instead of loading the BLOB data directly from the database. There are performance reasons that are well documented elsewhere that explain the intricate details better than I can, but basically the database slows and the amount of disk space it takes up expands as you store the images in the database.
If you decide to defy that advice and store the image directly in the database, you shouldn't be using phpMyAdmin as your main interface. Don't get me wrong, it's fully capable of uploading the image, but presumably you'll have some custom application interface that you should be using instead that also does application-level logic. But that's not what you asked, so to do this in phpMyAdmin, there should be a "Browse" button near the field on the phpMyAdmin Insert page. This requires your column be some appropriate sort of binary such as BLOB.

export image from lotus domino database

I'm a beginner with Lotus so I really need help about it.
my company gave me a database in lotus. This database include around 18,000 images which I must import in a new DB developed in MySQL.
When I tried to open it with notes designer/notes the fallowing message is showed:
You have insufficient access to perform this operation, I think there is a password that I
do not know.
for privacy reasons I can not post nothing about the db, sorry.
So, how can I export all images as easy way as possible?
First, you need to ensure you have sufficient access to the database. This means following:
If database resides on a server, ensure you are allowed to access the server and have Reader access to the database (you may need higher rights, see below for details);
If database resides on your workstation, you must ensure it's not locally encrypted by someone else or doesn't have Enforce ACL enabled;
With above in mind, exporting images from DB may require different approach depending on their location:
Are they stored as design elements (Image Resource), then all you have to do is to open the database in Domino Designer, go to Image Resources, select desired image resource and perform Resource -> Export;
Are they stored in documents, then this becomes a more complex task. You may use LotusScript or Java to iterate and process all documents containing images. For this, you would NotesRichTextItem class to retrieve NotesEmbedded object from each document. Alternative way would be to convert all rich-text field in document to MIME format using Call notesDocument.ConvertToMIME( conversionType, options) and process it after with NotesMIMEEntity class;
To access design of a database located on a Domino server you will need Designer rights.
Hopefully this will help.

Server backend: how to generate file paths for uploaded files?

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

creating a video database

I am interested in creating a video databse. My goal is to have a folder where my videos will be kept and each time I copy/delete a video the website that presents them should be updated to. the problem is I have no idea how to approach it.
Should I..
Use Sql and store a reference to each video location?
Have a script that checks all the time if new changes happen in that folder?
A package like joomla?
I am using ubuntu btw. I already have a simple html5 page, and I am presenting the videos using html5 video.
It depends on the size and the performance you want.
1.Way : use php to scan the folder and generate links on the fly
2.way : Use a database to store the file names and retrieve the names from the database and generate urls
pros and cons.
simple to implement , no changes in upload or download script. no database required.
You need have a database , little coding required for upload and also while genrating a page
You should make a db (format does not matter) and storing in it only file names of videos: the videos would be stored on hard drive.
Any operation on the web site will pass first on db for insert/update/delete videos records and then (maybe in a transaction context) on the file system.
This would be the standard approach to your question.

How to open a binary file directly from a database in c#?

Hey there,
i have a table with a field called "file" full of binary data (The File Itself) how can i open this binary data directly from the database on a click Event for example using c# ?
i dont want to download the file each time to view it .. just view it using the default viewer in the user's OS.
Any Ideas ??
To start off with other than an extremely trivial (throwaway) application I hope that you have setup some layers to abstract the DB access from your UI.
Ultimately your application will have to get the binary object from the DB table and present it as a file to the OS. The applications that come to mind typically want you to pass a filename to them to open them. In essence this means you have to download the file to the local machine with this technique.
The alternative would be to store the files on the filesystem of a server somewhere and place the name/location in your DB (nvarchar). Your application could get the filename/location and pass that to the viewer application.

Resources