malhal/CloudKit-PHP

Saving a CKAsset

Opened this issue · 12 comments

Is there a way to save a CKAsset?

It's possible, I had a look at upload assets section of the web services doc and it seems first there is a post of the asset record and then using curl to upload the file, both of which should be easy to do yes.

It might be helpful to know some additional detail about the kind of assets you'd like to work with. E.g. filesize would help understand if progress or cancellation support is needed, which would influence how the upload is done.

I haven't really used assets yet but one thing that crossed my mind is wether the asset record is not provided to clients until the data is uploaded, hopefully it isn't.

Thanks for your fast response - your code has been so helpful to me (I don't know php at all)! I am trying to update an existing record with a CKAsset that is an xml file.

I don't know the exact file size yet, I assume it will be less than 1 MB if that helps?

Also are you running it from a command line utility or via a page on a web server?

Via a page on a web server

I was thinking about if there is no feedback about the progress and if the page is reloaded, then it might end up creating the same asset record twice. However Apple say the file for the asset needs to be uploaded within 15mins so if that means they just throw away the asset record then it might be ok. Otherwise it's possible that the asset info with the url to upload to could be stored in the PHP session, then if the page is reloaded it can pull the existing asset info out of the session and then retry the upload again. I think it might be best to just do the simple case, a save asset method with a param to the file path to upload.

By the way have you checked Apples javascript API? That is designed for web pages.

This is all behind the scenes - I am just updating CloudKit from a server database every couple of hours. There is no front end.

So maybe it's not via a page on a web server but via a php script. I don't need to show any progress. I just can't find one php example of how to update a CKAsset.

Do you have an example of the "save asset method with a param to the file path to upload", and would that work with the existing files in this repository?

Ah right that's what I meant by command line. And most people run it periodically using cron. So we can forget all the session stuff then.

If no one else can do it then I can but I'm not free for a couple of days because trying to finish my sync framework.

I will be running this via cron. I will keep trying.