How to get file size from URL

Hey guys,


I need to get the file size of a MOV file from an URL in an array. It needs to be in the form of a string so I can put it in an UILabel. Is there documentation on this? Where do I start?

Answered by DTS Engineer in 226856022

Where do I start?

Two things:

  • To get the size of a URL, call

    URL.resourceValues(forKeys:)
    to get
    fileSize
    ,
    fileAllocatedSize
    ,
    totalFileSize
    , or
    totalFileAllocatedSize
    , depending on your specific requirements.
  • To format that as a string, use

    ByteCountFormatter
    .

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Accepted Answer

Where do I start?

Two things:

  • To get the size of a URL, call

    URL.resourceValues(forKeys:)
    to get
    fileSize
    ,
    fileAllocatedSize
    ,
    totalFileSize
    , or
    totalFileAllocatedSize
    , depending on your specific requirements.
  • To format that as a string, use

    ByteCountFormatter
    .

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

why don't you just use curl?

I'm new to SWIFT. I'm not sure if I've heard of it. The SWIFT documentation doesn't help me, and a google search for "swift cURL" just shows a bunch of tips for curly hair. What would be the benefits of using cURL?

How to get file size from URL
 
 
Q