Skip to main content
Known Participant
September 1, 2011
Question

ByteArray objects cannot be converted to strings

  • September 1, 2011
  • 1 reply
  • 4744 views

I am trying to manage images using cf and mysql. What a pain! My SQL doesn't play nice with images so I'm finding out.

Here is what I have done. I have blobs enabled in mysol admin. Now that I did that, I can't just read the image values I uploaded to the server, I have to read a byteArray. How do I do this??

This is the code giving me a problem:

<cfif projMan.thumb is true>

#toString(thumb)#

</cfif>

My cfif is throwing this error.

I also need it to be read if I update a record.. this is my insert update code:

<cffile Accept="image/*" action = "upload" Destination="D:\wwwroot\mysite\images\contentfile\" fileField = "MYFile" nameConflict = "overwrite">
<cfset uploadedfile = cffile.serverfile>

<cfif form.id EQ 0>
<cfquery name="InsertDetails" datasource="#sitedatasource#">
    INSERT INTO recipes
    (title, Body, thumb, descript, categoryID)
    VALUES
(<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.title#">,
<cfqueryparam cfsqltype="cf_sql_longvarchar" value="#form.Body#">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#uploadedfile#">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.descript#">,
<cfqueryparam value="#form.categoryID#" cfsqlType="CF_SQL_INTEGER">)
</cfquery>

<cfelse>

<cfquery name="UpdateDetails" datasource="#sitedatasource#">
UPDATE recipes
SET
recipes.title=<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.title#">,
recipes.Body=<cfqueryparam cfsqltype="cf_sql_longvarchar" value="#form.Body#">,
<cfif uploadedfile is true>
recipes.thumb=<cfqueryparam cfsqltype="cf_sql_varchar" value="#uploadedfile#">,
</cfif>
recipes.descript=<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.descript#">,
recipes.CategoryID=<cfqueryparam value="#form.categoryID#" cfsqlType="CF_SQL_INTEGER">
WHERE recID = <cfqueryparam value="#form.ID#" cfsqlType="CF_SQL_INTEGER">
</cfquery>

</cfif>

Can anyone help me out? I'm hoping this is a simple solution.. I have been at this for 2 days now, and this is my last issue. It is also my first time using mysql for image management.

Thank you.

This topic has been closed for replies.

1 reply

Inspiring
September 1, 2011

Here is what I have done. I have blobs enabled in mysol

admin. Now that I did that, I can't just read the image

values I uploaded to the server, I have to read a byteArray.

How do I do this??

The description of the problem and the code are giving conflicting stories. What is it you want to store in your database - the actual content of the images or just the file names (ie "myImage.png")?

Can you post the full error message?

Known Participant
September 1, 2011

yes, just the myImage.png is to go into the db. There is no error, it just won't write the file name to the DB for me to access it later. Driving me crazy, SQL is easier than this.. I don't get where the problem is.

I fixed the ByteArray issue, but now I can't get it to write to the db.

Inspiring
September 1, 2011

There is no error, it just won't write the file name to

the DB for me to access it later.

You need to be more specific. First, is the problem with your UPDATE or INSERT query? Second what do you mean by "won't write the file name"? Is the file name being erased, not updated, or something else ...?