Upload file to ColdFusion database

I just want to upload a file to my database using ColdFusion. I understand how to upload an image to a directory, but I would like to place it directly in the database.

I set the database field to varbinary (MAX) to accept the image and to have the stored procedure insert it. Currently, my code for uploading an image to my file system:

<cfif isdefined("form.FileUploadImage")> 
            <cffile action="upload" filefield="FileUploadImage" destination="#uploadfolder#" nameconflict="overwrite" accept="image/*" > 
</cfif>

I obviously left part of the support code, but in fact all I have to do is get a binary representation of the file stored in memory, not in the file system.

Any experts that can help?

Thanks George

+3
source share
2 answers

Something like that?

<cfquery>
  INSERT INTO Image (Jpg) 
  VALUES (
    <cfqueryparam CFSQLType="CF_SQL_BLOB"
                  value="#ToBase64(FileReadBinary(uploadedFilePath))#">
</cfquery>

, , <cfimage> (CF8 +)

+6

:

<cfqueryparam cfsqltype="cf_sql_blob"
              value="#FileReadBinary(FORM.FileUploadImage)#">
+4

Source: https://habr.com/ru/post/1735839/


All Articles