Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Coffee corner » saving and reading pdf file, binary file, image file in mysql
saving and reading pdf file, binary file, image file in mysql [message #57087] Sun, 23 May 2021 14:10 Go to next message
BetoValle is currently offline  BetoValle
Messages: 142
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member
Hi,

I did a test by uploading a pdf file to a variable string and then saved it to mysql. Then I read the content for string, and saved it as a pdf. The result was totally incorrect. How can I do this considering pdf, binary and image files?

            String pdf="file.pdf";
            String bf ="file.exe";
            String if ="file.png";
        	
	    //how to load Files to save in mysql?;
            
            sql.Begin();
            String st="INSERT INTO test ";
            st += "(PDF,BF,IF)";
            st += " values (?,?,?)";  
            sql.Execute ( , , );
            sql.Commit();


            String st="select * from test ";
            sql.Execute (st);
            while ( sql.Fetch() )
            {
                ? SQL["PDF"]
                ? SQL["BF"]
                ? SQL["IF"]	
             }            

            //how to write content in files ?
              SaveFile(fpdf,?); 
              SaveFile(fbf,?); 
              SaveFile(fif,?); 



Thanks!
Re: saving and reading pdf file, binary file, image file in mysql [message #57090 is a reply to message #57087] Sun, 23 May 2021 21:10 Go to previous messageGo to next message
BetoValle is currently offline  BetoValle
Messages: 142
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member
Hi, I had some success with pdf files:

mysql (I also successfully tested it on sqlite3)
//it may be necessary to increase mysql limits in the "my.ini" file, it was my situation because I tested a 23mb file

max_allowed_packet = 64M or (1073741824)
and
innodb_log_file_size=255M

	    String f="testeOrig.pdf";
	    String f2="testeDest.pdf";
	    String s=LoadFile(f);
	    String str=Base64Encode(s); 
	
            sql.Begin();
            String st="INSERT INTO test ";
            st += "(ID,TEXT,BF)";
            st += " values (?,?,?)";  
            sql.Execute (st,1,AsString(2),str);
            sql.Commit();
               
            Value v;
            String st="select * from test ";
            sql.Execute (st);
            while ( sql.Fetch() )
            {
	        v  = AsString ( sql["BF"] );
	    }
        
            String str=Base64Decode(v); 
            SaveFile(f2,str); 




Thanks!


Re: saving and reading pdf file, binary file, image file in mysql [message #57093 is a reply to message #57087] Mon, 24 May 2021 16:39 Go to previous message
deep is currently offline  deep
Messages: 234
Registered: July 2011
Location: Bangalore
Experienced Member
Hi

Check field / column type as BLOB or LONGVARBINARY.


Warm Regards

Deepak
Previous Topic: select file with windows explorer
Next Topic: Compile under Mac M1 for intel
Goto Forum:
  


Current Time: Sat Dec 04 11:51:41 CET 2021

Total time taken to generate the page: 0.01091 seconds