Event action - File creation

Hi Folks,

Does anyone know if it’s possible to upload files using an event action?

I’m looking to retrieve the the raw content via cURL and then save the file to a ‘file’ object type.

Using a widget for this use case wouldn’t be ideal.

Regards,
Shervin

Hey,

Yes, it is possible, have a look at cs.write_file() in Code Studio help panel.

You can also store file content directly into lets say an Image property for example with the below code

let userRecord = cs.record(123);
let imgData = 'data:' + rsp['img_content_type'] + ';base64,' + cs.base64_encode(rsp['img_content']);
userRecord.set(cs.ref('refToImgField'), imgData)

Hi Ged,

Thanks for your response. I’ve had a go at using cs.write_file() which does create a file but the mime/type is always ‘text/plain’ and doesn’t allow me to view it, so either I’m missing a step here or this method won’t be suitable.

This is the file content I’m getting back from the curl request.

Just read something about cs.write_file()… Out of interest what sort of files are you trying to store?

Ah, I suspected it might be for a different use case.

the files will be mainly (doc, tif, pdf, png, jpg).