Get the file size of a file in iCloud Drive

When a file named a.txt is not downloaded locally, the iCloud Drive folder actually only contains a placeholder named .a.txt.icloud (that is still displayed as a.txt by the Finder) with a very small file size, something like 176 bytes. How can I get the original file size, like the Finder displays?

  • I'm running into the same issue. I've looked through all of the NSURL resource keys and none of them will return the size of the original (yet to be downloaded) file.

    This is frustrating because the Finder seems to know what the size is, and I'd really like to know where it gets that information.

  • I still have to come up with a solution myself.

Add a Comment

Replies

After a little more investigation, I did find a hack. It turns out that .iCloud files are actually property list files, and you can read them using the low-level file API.

For example, I have a file named 02.data on my iCloud drive that's 134MB. It's placeholder file (.02.data.icloud) contains this:

{
    NSURLFileResourceTypeKey = NSURLFileResourceTypeRegular;
    NSURLFileSizeKey = 134210392;
    NSURLNameKey = "02.data";
}

Which is exactly the info I was looking for!

No let's hope this doesn't change with the next OS! :P

  • Thanks for posting your solution! Is there a specific low-level file API that you used? Did you parse the file as text with a specific encoding?

Add a Comment

It turns out that .iCloud files are actually property list files, and you can read them using the low-level file API.

Oi vey! don’t do that. The format of these files is not considered API and you run the risk of your app breaking in future releases of the system.

I don’t know what the correct way to do this is. If you’d like to get a definitive answer to that question, I encourage you to open a DTS tech support incident so that one of us can allocate time to researching this properly.

Although it’s probably best to wait until after WWDC because we’re fully committed to the conference next week.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • I already filed a bug report FB11944561 in January 2023 mentioning this issue and just filed another explicit issue FB12224338. Since Apple is aware of this problem, I don't think anybody should use a TSI, or buy extra TSIs, to get a solution.

  • Thanks, Quinn

    I'll look for changes in the next macOS, and loop back around to this in late summer if it's still unresolved.

Add a Comment