Skip to content
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
5 changes: 5 additions & 0 deletions lib/Controller/AttachmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\Files\IMimeTypeDetector;
use OCP\Files\InvalidPathException;
use OCP\IL10N;
use OCP\IRequest;
use OCP\Util;
Expand Down Expand Up @@ -133,6 +134,10 @@ public function uploadAttachment(string $token = ''): DataResponse {
}
}
return new DataResponse(['error' => 'No uploaded file'], Http::STATUS_BAD_REQUEST);
} catch (InvalidPathException $e) {
$this->logger->error('Upload error', ['exception' => $e]);
$error = $e->getMessage() ?: 'Upload error';
return new DataResponse(['error' => $error], Http::STATUS_BAD_REQUEST);
} catch (Exception $e) {
$this->logger->error('Upload error', ['exception' => $e]);
return new DataResponse(['error' => 'Upload error'], Http::STATUS_BAD_REQUEST);
Expand Down
6 changes: 5 additions & 1 deletion lib/Service/AttachmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use OCP\Constants;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IFilenameValidator;
use OCP\Files\IMimeTypeDetector;
use OCP\Files\InvalidPathException;
use OCP\Files\IRootFolder;
Expand All @@ -35,7 +36,8 @@ public function __construct(private IRootFolder $rootFolder,
private ShareManager $shareManager,
private IPreview $previewManager,
private IMimeTypeDetector $mimeTypeDetector,
private IURLGenerator $urlGenerator) {
private IURLGenerator $urlGenerator,
private IFilenameValidator $filenameValidator) {
}

/**
Expand Down Expand Up @@ -263,6 +265,7 @@ public function uploadAttachment(int $documentId, string $newFileName, $newFileR
}
$saveDir = $this->getAttachmentDirectoryForFile($textFile, true);
$fileName = self::getUniqueFileName($saveDir, $newFileName);
$this->filenameValidator->validateFilename($fileName);
$savedFile = $saveDir->newFile($fileName, $newFileResource);
return [
'name' => $fileName,
Expand Down Expand Up @@ -293,6 +296,7 @@ public function uploadAttachmentPublic(?int $documentId, string $newFileName, $n
$textFile = $this->getTextFilePublic($documentId, $shareToken);
$saveDir = $this->getAttachmentDirectoryForFile($textFile, true);
$fileName = self::getUniqueFileName($saveDir, $newFileName);
$this->filenameValidator->validateFilename($fileName);
$savedFile = $saveDir->newFile($fileName, $newFileResource);
return [
'name' => $fileName,
Expand Down
6 changes: 5 additions & 1 deletion src/components/Editor/MediaHandler.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ export default {
})
.catch((error) => {
logger.error('Uploading attachment failed', { error })
showError(t('text', 'Uploading attachment failed.'))
if (error.response?.data.error) {
showError(t('text', 'Uploading attachment failed: {error}', { error: error.response.data.error }))
} else {
showError(t('text', 'Uploading attachment failed.'))
}
})
.then(() => {
this.state.isUploadingAttachments = false
Expand Down