public function chunkedUpload($file, $filename = false, $path = '', $overwrite = true, $offset = 0, $uploadID = null)
    {
        if (file_exists($file)) {
            if ($handle = @fopen($file, 'r')) {
            	// Seek to the correct position on the file pointer
			    fseek($handle, $offset);

                // Read from the file handle until EOF, uploading each chunk
                while ($data = fread($handle, $this->chunkSize)) {
                    // Open a temporary file handle and write a chunk of data to it
                    $chunkHandle = fopen('php://temp', 'rw');
                    fwrite($chunkHandle, $data);
                    
                    // Set the file, request parameters and send the request
                    $this->OAuth->setInFile($chunkHandle);
                    $params = array('upload_id' => $uploadID, 'offset' => $offset);
                    
                    try {
                    	// Attempt to upload the current chunk
                    	$response = $this->fetch('PUT', self::CONTENT_URL, 'chunked_upload', $params);
                    } catch (Exception $e) {
                    	$response = $this->OAuth->getLastResponse();
                    	if ($response['code'] == 400) {
                    		// Incorrect offset supplied, return expected offset and upload ID
                    		$uploadID = $response['body']->upload_id;
                    		$offset = $response['body']->offset;
                    		return array('uploadID' => $uploadID, 'offset' => $offset);
                    	} else {
                    		// Re-throw the caught Exception
                    		throw $e;
                    	}
                    }
                                     
                    // On subsequent chunks, use the upload ID returned by the previous request
                    if (isset($response['body']->upload_id)) {
                        $uploadID = $response['body']->upload_id;
                    }
                    
                    // Set the data offset
                    if (isset($response['body']->offset)) {
                        $offset = $response['body']->offset;
                    }

                    // Close the file handle for this chunk
                    fclose($chunkHandle);
                }

                // Complete the chunked upload
                $filename = (is_string($filename)) ? $filename : basename($file);
                $call = 'commit_chunked_upload/' . $this->root . '/' . $this->encodePath(rtrim($path, '/') . '/' . $filename);
                $params = array('overwrite' => (int) $overwrite, 'upload_id' => $uploadID);
                $response = $this->fetch('POST', self::CONTENT_URL, $call, $params);
                return $response;
            } else {
                throw new Exception('Could not open ' . $file . ' for reading');
            }
        }
        
        // Throw an Exception if the file does not exist
        throw new Exception('Local file ' . $file . ' does not exist');
    }