public function share_file($fileid, $businesscheck = true) {
        // Sharing the file, this requires a PUT request with data within it. We cannot use
        // the standard PUT request 'CURLOPT_PUT' because it expects a file.
        $data = array('shared_link' => array('access' => 'open', 'permissions' =>
            array('can_download' => true, 'can_preview' => true)));
        $options = array(
            'CURLOPT_CUSTOMREQUEST' => 'PUT',
            'CURLOPT_POSTFIELDS' => json_encode($data)
        );
        $this->reset_state();
        $result = $this->request($this->make_url("/files/$fileid"), $options);
        $result = json_decode($result);

        if ($businesscheck) {
            // Checks that the user has the right to share the file. If not, throw an exception.
            $this->reset_state();
            $this->head($result->shared_link->download_url);
            $info = $this->get_info();
            if ($info['http_code'] == 403) {
                throw new moodle_exception('No permission to share the file');
            }
        }

        return $result->shared_link;
    }