Skip to content

Commit

Permalink
fix: fixed download error for some formats. a separate method has bee…
Browse files Browse the repository at this point in the history
…n allocated for obtaining mime type by format name
  • Loading branch information
rivexe committed Mar 19, 2024
1 parent 55ffeb5 commit 70cbd96
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions controller/editorcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -1274,9 +1274,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 @@ -1391,6 +1391,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

0 comments on commit 70cbd96

Please sign in to comment.