Skip to content

Commit

Permalink
wip: Allow the browser to upload directly a document through the Stor…
Browse files Browse the repository at this point in the history
…age #1004
  • Loading branch information
cnouguier committed Dec 3, 2024
1 parent 90d86c0 commit 8f8a006
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/client/exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 24 additions & 2 deletions core/client/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
},
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8f8a006

Please sign in to comment.