How can I store images in BLOB? - sql

I can not find useful code for how storing the images into BLOB ,please help me with some code and also can I show those images from MySQL to my desktop pane in GUI?

If the image is located on your MySQL host, you could use the LOAD_FILE() command for storing an image in a BLOB:
-- Using the following table as an example:
CREATE TABLE MyTable (
image BLOB
);
-- This will insert a file in a BLOB column.
INSERT INTO MyTable (image) VALUES(LOAD_FILE('/tmp/image.png'));
Make sure that the image file is readable by MySQL, and also make sure that your MySQL user has the FILE privilege.
To grant the FILE privilege, log-in as root and execute:
GRANT FILE ON *.* TO 'mysql_user'#'localhost';

Easiest way is to store the contents of some binary image file in the blob, extract them, write them to a file and open that file with an image file parser of some kind. Or, if you're really tricky, use that same image parser to read the data from memory directly after pulling the blob out of the DB.
I'm assuming you've got some sort of ImagePane widget that can handle the GUI display if you can provide an image file to it.

Related

how to read a tab delimited .txt file and insert into oracle table

I want to read a tab delimited file using PLSQL and insert the file data into a table.
Everyday new file will be generated.
I am not sure if external table will help here because filename will be changed based on date.
Filename: SPRReadResponse_YYYYMMDD.txt
Below is the sample file data.
Option that works on your own PC is to use SQL*Loader. As file name changes every day, you'd use your operating system's batch script (on MS Windows, these are .BAT files) to pass a different name while calling sqlldr (and the control file).
External table requires you to have access to the database server and have (at least) read privilege on its directory which contains those .TXT files. Unless you're a DBA, you'll have to talk to them to provide environment. As of changing file name, you could use alter table ... location which is rather inconvenient.
If you want to have control over it, use UTL_FILE; yes, you still need to have access to that directory on the database server, but - writing a PL/SQL script, you can modify whatever you want, including file name.
Or, a simpler option, first rename input file to SPRReadResponse.txt, then load it and save yourself of all that trouble.

How to store files on mysql server

I need to send files like an image or pdf to a mysql database from a vb.NET form. How can i do this? is there a specific column type? what type of sql query should i write to send the file?
You can upload and save file in a folder in the server, and the filename or path of the file in the database along with an unique identifier.
If you really want to save the file in database (which is highly not recommended) you can use blob datatype. but it is mostly recommended to save the file pathname in the database column as a string, while you store the file to a local storage, and when you need to display the file, you just get the path saved in your database column, this should give you the file.

Use SQL to create a text file and save to a varbinary blob file without writing to disk

I currently have a working SQL stored procedure that is using BCP and xp_cmdshell to create a text file on the system disk and then upload that file into a varbinary field in an Attachments table.
What I'm needing to know is if it is possible to do this without writing a file to disk as part of the process?
UPDATED DETAILS
I am using MSSQL 2014 and the intention is to load the text file (a csv file actually) into the database so that other users can download it.
Is Text File is generating only for pusing content into varbinary fields?if so why dont you use simply convert the content directly into varbinary using convert function and push directly the results into table field.
If i am getting wrong correct me pls.

how to read data stored in blobs

my application datbase in postgressql and from the document i understand that it store few data in a blob and from the table i can only get the oid of it.
is there any possibility to read the content from these blobs? if yes, could someone share the knowhow?
From the OID, a file with the contents of the large object can be exported.
Either client-side (psql):
\lo_export oid-to-export /path/to/a/file
Or server-side in SQL (creates the file on the server, beware that postgres must have the permission to write into the destination directory).
SELECT lo_export(oid-to-export, '/path/to/a/file');

Saving an image to SQL Server 2008?

I have this:
Create Proc CrearNuevoImagen
#imagen image
AS
INSERT INTO
Imagenes(imagen)
VALUES(
#imagen
)
I see that #imagen is of type 'image'.
My question is save that I have an .jpg image, on my front-end (my asp.net website code), how could I convert the .jpg image to fit into the 'image'-type column? Or does the SQL Server automatically do this for me?
Save your image object to a MemoryStream. Then you can take the byte array out of the memory stream and pass that to SQL Server to save it in your "image" or "varbinary" column.
The image column type is just a binary container; SQL Server doesn't interpret or modify the data you store there at all.
See http://www.informit.com/articles/article.aspx?p=377078
The IMAGE type is just a name for a type that can store a byte array. It is now deprecated and you should use the VARBINARY(MAX) type instead. Saving JPG files into the back end database is actually a bit more complex if you care about performance, because of the need to avoid these relatively large files to be copied into memory. Have a look at Download and Upload images from SQL Server via ASP.Net MVC for an example of efficient streaming of image files stored in SQL Server BLOB fields.