             return errorWithCode(NSURLErrorBadURL, failureReason: "The URL is not reachable: \(URL)")
         }
 
+        let bodyContentLength: UInt64
+        var fileAttributesError: NSError?
+
+        if let
+            path = URL.path,
+            attributes = NSFileManager.defaultManager().attributesOfItemAtPath(path, error: &fileAttributesError),
+            fileSize = (attributes[NSFileSize] as? NSNumber)?.unsignedLongLongValue
+        {
+            bodyContentLength = fileSize
+        } else {
+            return errorWithCode(NSURLErrorBadURL, failureReason: "Could not fetch attributes from the URL: \(URL)")
+        }
+
         if let bodyStream = NSInputStream(URL: URL) {
-            let bodyPart = BodyPart(headers: headers, bodyStream: bodyStream)
+            let bodyPart = BodyPart(headers: headers, bodyStream: bodyStream, bodyContentLength: bodyContentLength)
             self.bodyParts.append(bodyPart)
         } else {
             let failureReason = "Failed to create an input stream from the URL: \(URL)"

        let headers = contentHeaders(name: name, fileName: fileName, mimeType: mimeType)
        let bodyStream = NSInputStream(data: data)
        let bodyContentLength = UInt64(data.length)
        let bodyPart = BodyPart(headers: headers, bodyStream: bodyStream)

        self.bodyParts.append(bodyPart)
    }

    class BodyPart {
        let headers: [String: String]
        let bodyStream: NSInputStream
        let bodyContentLength: UInt64
        var hasInitialBoundary = false
        var hasFinalBoundary = false

        init(headers: [String: String], bodyStream: NSInputStream, bodyContentLength: UInt64) {
            self.headers = headers
            self.bodyStream = bodyStream
            self.bodyContentLength = bodyContentLength
        }
    }

