How to store attachment when creating content with JS API

Enonic version: 6.7.0-RC5
OS: Windows

Hi! I am trying to store an unstructured content with one or more files as attachments. (That way I don’t need to store the files as separate contents.)

From the docs I find that there is an attachments-property in the params:!/module-lib_xp_content.html#.create
However, when replicating this, no attachments are stored.

(I note that the ‘attachments’ param is not listed in the list of params, but just in the example code, where the param is not actually used)

Is it possible to add attachments upon creating content with the API, and do you have an example where this is used? Or is it not possible to save attachments to unstructured content?

I have tried creating content in the content studio with the AttachmentUploader input type, and see that the attachments are saved correctly then. The JSON blob I send is input is similar to the one saved using this method.

I am afraid this is currently not supported from the JavaScript API.

You can use createMedia() , but that does not work with unstructured type.

Do you know if it will be supported anytime soon?

I was trying to do this based on feedback from @tsi on my formbuilder app, but I guess I will have to continue saving the attachment outside the content for now.

Or is it possible to do using the Java API? Since the AttachmentUploader works, I assume there is a way, as custom content types are basically unstructured content?

I think it should be supported in JS, unless there was a reason not to have it that I’m forgetting.
It’s too late to have it in 6.7. Maybe in 6.8, but someone else should confirm that.

It is possible to do it now using the Java API, look at ContentService.create() and CreateContentParams , CreateAttachments.

1 Like

I’ll have a look at those later today.

I often find myself syncing data from old external api’s.
The data typically become some js object which can be serialized as json.
Then some of the data gets cleaned up and stored as content so I can be queried, sorted, filtered, etc.

For debugging and other purposes it would be nice if I could store the raw data, or the json as attachment on the content.

Did this feature make it into 6.8?
If so are there any documentation on how to do it?

Could be my typical blindness, but I’m not seeing it here.!/module-lib_xp_content.html#.create

Since it’s a json object, I could use unstructured and store it in data.

But then no fields can be edited.

Perhaps x-data is the place to store it?

Will have @rmy answer this. I think it’s possible by now, but we need a good example of it. If it’s not possible, then we will surely put it in ASAP.

Sorry, we do not have that functionality yet. I will fight for this to be part of 6.10 release in February.

1 Like

@cwe I guess what you are really looking for is support for input fields that are not visible for editors?

That would also be nice, and read-only input’s :slight_smile:

1 Like

We added this to our backlog in Q1. Hopefully 6.10.