Load file into binary field

loop
importfilename=""
importfilename=importfolder+array(newimportfilelist,counter,¶)
addrecord
zlog importfilename
zlog fileload(importfilename)
Contents=texttobinary(fileload(importfilename),4)

counter = counter + 1
until counter > importsize

I am attempting to load files of markdown into a binary field. I am trying to use the texttobinary function to convert from text to binary - although it is raising an error that the data cannot be binary or numeric data. Is there a better way to import my text into a field within the db?

Thank you,
Robb

The result of a fileload( function is already binary. It’s the texttobinary( function that is complaining that its parameter isn’t text. So you just need to change

Contents=texttobinary(fileload(importfilename),4)

to

Contents=fileload(importfilename)

Is your Contents field really binary? If so, I am wondering why. Since Markdown is text, I would think you would want to use a Text field, not a Binary field. That way you will be able to do things like search and manipulate the Markdown text, which I assume is why you want to bring it into the database.

So what I think you want to do is make the Contents field a text field, and use this code:

Contents = binarytotext(fileload(importfilename))

Note that you don’t need to specify the encoding, because UTF8 is the default.