From 8f8a0068dfd7a3348f84936df1af76521645abc1 Mon Sep 17 00:00:00 2001 From: cnouguier Date: Tue, 3 Dec 2024 14:38:32 +0100 Subject: [PATCH] wip: Allow the browser to upload directly a document through the Storage #1004 --- core/client/exporter.js | 2 +- core/client/storage.js | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/core/client/exporter.js b/core/client/exporter.js index 41a718b6d..7ca104a5f 100644 --- a/core/client/exporter.js +++ b/core/client/exporter.js @@ -72,7 +72,7 @@ const ExporterQueue = { } // close the notification request.notification() - // donwload the file + // download the file if (params.SignedUrl) { // Use an iframe to download the file // see https://github.com/socketio/socket.io/issues/4436 diff --git a/core/client/storage.js b/core/client/storage.js index dbbed1a7f..6822323a7 100644 --- a/core/client/storage.js +++ b/core/client/storage.js @@ -45,7 +45,7 @@ export const Storage = { return response } catch (error) { dismiss() - logger.error(`Cannot upload ${key} on ${service.path}`, error) + logger.error(`[KDK] Cannot upload ${file} with key '${key}'`, error) throw error } }, @@ -78,10 +78,32 @@ export const Storage = { }) } catch (error) { dismiss() - logger.error(`Cannot download ${key} on ${service.path}`, error) + logger.error(`[KDK] Cannot download '${file}' with key '${key}'`, error) throw error } }, + async export (options) { + const { file, key, context } = options + const service = this.getService(context) + const response = await service.create({ + id: key, + command: 'GetObject', + expiresIn: 60, + ResponseContentDisposition: `attachment; filename="${file}"` + }) + if (response.SignedUrl) { + let iframe = document.getElementById('export-hidden-frame') + if (!iframe) { + iframe = document.createElement('iframe') + iframe.id = 'export-hidden-frame' + iframe.style.display = 'none' + document.body.appendChild(iframe) + } + iframe.src = response.SignedUrl + } else { + logger.error(`[KDK] Cannot export ${file} with key '${key}'`) + } + }, async getObjectUrl (options) { const { key, context } = options // Ensure service is created