Skip to content

Commit

Permalink
Merge pull request #6214 from nextcloud/backport/6211/stable28
Browse files Browse the repository at this point in the history
[stable28] fix(attachments): Uploading of attachments from public shares
  • Loading branch information
juliusknorr authored Aug 28, 2024
2 parents 5e00fb7 + eac32b4 commit 2e65baa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions lib/Controller/AttachmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function insertAttachmentFile(string $filePath): DataResponse {
#[NoAdminRequired]
#[PublicPage]
#[RequireDocumentSession]
public function uploadAttachment(?string $shareToken = null): DataResponse {
public function uploadAttachment(?string $token = null): DataResponse {
$documentId = $this->getSession()->getDocumentId();

try {
Expand All @@ -137,8 +137,8 @@ public function uploadAttachment(?string $shareToken = null): DataResponse {
throw new Exception('Could not read file');
}
$newFileName = $file['name'];
if ($shareToken) {
$uploadResult = $this->attachmentService->uploadAttachmentPublic($documentId, $newFileName, $newFileResource, $shareToken);
if ($token) {
$uploadResult = $this->attachmentService->uploadAttachmentPublic($documentId, $newFileName, $newFileResource, $token);
} else {
$userId = $this->getSession()->getUserId();
$uploadResult = $this->attachmentService->uploadAttachment($documentId, $newFileName, $newFileResource, $userId);
Expand Down
12 changes: 6 additions & 6 deletions src/components/Editor/MediaHandler.vue
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ export default {
return Promise.all(uploadPromises)
.catch(error => {
logger.error('Uploading multiple images failed', { error })
showError(error?.response?.data?.error || error.message)
logger.error('Uploading multiple attachments failed', { error })
showError(t('text', 'Uploading multiple attachments failed.'))
})
.then(() => {
this.state.isUploadingAttachments = false
Expand All @@ -145,8 +145,8 @@ export default {
)
})
.catch((error) => {
logger.error('Uploading image failed', { error })
showError(error?.response?.data?.error)
logger.error('Uploading attachment failed', { error })
showError(t('text', 'Uploading attachment failed.'))
})
.then(() => {
this.state.isUploadingAttachments = false
Expand All @@ -173,8 +173,8 @@ export default {
null, response.data?.dirname,
)
}).catch((error) => {
logger.error('Failed to insert image path', { error })
showError(error?.response?.data?.error || error.message)
logger.error('Failed to insert from Files', { error })
showError(t('text', 'Failed to insert from Files'))
}).then(() => {
this.state.isUploadingAttachments = false
})
Expand Down
2 changes: 1 addition & 1 deletion src/services/SessionApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export class Connection {
+ '?documentId=' + encodeURIComponent(this.#document.id)
+ '&sessionId=' + encodeURIComponent(this.#session.id)
+ '&sessionToken=' + encodeURIComponent(this.#session.token)
+ '&shareToken=' + encodeURIComponent(this.#options.shareToken || '')
+ '&token=' + encodeURIComponent(this.#options.shareToken || '')
return this.#post(url, formData, {
headers: {
'Content-Type': 'multipart/form-data',
Expand Down

0 comments on commit 2e65baa

Please sign in to comment.