CloudKit-PHP icon indicating copy to clipboard operation
CloudKit-PHP copied to clipboard

Saving a CKAsset

Open inPhilly opened this issue 8 years ago • 12 comments

Is there a way to save a CKAsset?

inPhilly avatar Sep 18 '17 13:09 inPhilly

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.

malhal avatar Sep 18 '17 14:09 malhal

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.

inPhilly avatar Sep 18 '17 14:09 inPhilly

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

inPhilly avatar Sep 18 '17 14:09 inPhilly

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

malhal avatar Sep 18 '17 14:09 malhal

Via a page on a web server

inPhilly avatar Sep 18 '17 14:09 inPhilly

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.

malhal avatar Sep 18 '17 14:09 malhal

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

malhal avatar Sep 18 '17 14:09 malhal

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

inPhilly avatar Sep 18 '17 15:09 inPhilly

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.

inPhilly avatar Sep 18 '17 15:09 inPhilly

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?

inPhilly avatar Sep 18 '17 15:09 inPhilly

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.

malhal avatar Sep 18 '17 15:09 malhal

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

inPhilly avatar Sep 18 '17 15:09 inPhilly