Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed download error for some formats #966

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions controller/editorcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -1257,9 +1257,9 @@ public function download($fileId, $toExtension = null, $template = false) {
$fileNameWithoutExt = substr($fileName, 0, strlen($fileName) - strlen($ext) - 1);
$newFileName = $fileNameWithoutExt . "." . $toExtension;

$formats = $this->config->formatsSetting();
$mimeType = $this->config->getMimeType($toExtension);

return new DataDownloadResponse($newData, $newFileName, $formats[$toExtension]["mime"][0]);
return new DataDownloadResponse($newData, $newFileName, $mimeType);
}

/**
Expand Down
21 changes: 21 additions & 0 deletions lib/appconfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,27 @@ public function getFormats() {
return json_decode($formats, true);
}

/**
* Get the mime type by format name
*
* @param string $ext - format name
*
* @return string
*/
public function getMimeType($ext) {
$onlyofficeFormats = $this->getFormats();
$result = "text/plain";

foreach ($onlyofficeFormats as $onlyOfficeFormat) {
if ($onlyOfficeFormat["name"] === $ext && !empty($onlyOfficeFormat["mime"])) {
$result = $onlyOfficeFormat["mime"][0];
break;
}
}

return $result;
}

/**
* DEMO DATA
*/
Expand Down
Loading