File upload via web service


(Brynlewis) #1

I am having trouble uploading a file using the web service API.


I am not sure what value this property should have:

FileContentBase64



I have been able to clone an existing file asset and to upload to it. The filename changes, but the contents of the file are not correct.



Also, I can't see how to create a file asset from scratch.


(Benjamin Pearson) #2

[quote]
I am having trouble uploading a file using the web service API.



I am not sure what value this property should have:

FileContentBase64



I have been able to clone an existing file asset and to upload to it. The filename changes, but the contents of the file are not correct.



Also, I can't see how to create a file asset from scratch.

[/quote]



It looks like you need to Base 64 encode the file contents.


(Aleks Bochniak) #3

There is a keyword for this:


^base64encode



Usage example:



%asset_contents^base64encode%


(Benjamin Pearson) #4

[quote]
Also, I can't see how to create a file asset from scratch.

[/quote]



Unfortunately, the CreateAsset needs extra information passed to it, in order to create the File Asset, otherwise the CreateAsset just throws an error. This is a standard Matrix convention, when creating a file asset in the backend, you need to supply a file to it in order for it to be created.



EDIT: This feature was added to 3.26.3 and higher. I did not see this the first time around since I was using an older version. With CreateAsset, to create a file asset, set the TypeCode to 'file', and supply a filename and the contents of the file (base64 encoded).