diff --git a/packages/web-app-files/src/components/AppBar/AppBar.vue b/packages/web-app-files/src/components/AppBar/AppBar.vue index 06542f7d1b6..be2334e7c06 100644 --- a/packages/web-app-files/src/components/AppBar/AppBar.vue +++ b/packages/web-app-files/src/components/AppBar/AppBar.vue @@ -546,30 +546,36 @@ export default { async addAppProviderFile(fileName) { try { const parent = this.currentFolder.fileId + const publicToken = (this.$router.currentRoute.params.item || '').split('/')[0] const configUrl = this.configuration.server const appNewUrl = this.capabilities.files.app_providers[0].new_url.replace(/^\/+/, '') - const url = configUrl + appNewUrl + `?parent_container_id=${parent}&filename=${fileName}` - - const headers = new Headers() - if (!this.isPublicFilesRoute) { - headers.append('Authorization', 'Bearer ' + this.getToken) - headers.append('X-Requested-With', 'XMLHttpRequest') - } else { - headers.append( - 'Authorization', - 'Basic ' + Buffer.from('public:' + this.publicLinkPassword).toString('base64') - ) + const url = + configUrl + + appNewUrl + + `?parent_container_id=${parent}&filename=${encodeURIComponent(fileName)}` + + const headers = { + 'X-Requested-With': 'XMLHttpRequest', + ...(this.isPublicFilesRoute && { + 'public-token': publicToken + }), + ...(this.publicLinkPassword && { + Authorization: + 'Basic ' + + Buffer.from(['public', this.publicLinkPassword].join(':')).toString('base64') + }), + ...(this.getToken && { + Authorization: 'Bearer ' + this.getToken + }) } - const response = await fetch(encodeURI(url), { + const response = await fetch(url, { method: 'POST', headers }) - await response.json() - - if (!response.ok) { + if (response.status !== 200) { const message = `An error has occured: ${response.status}` throw new Error(message) }