Skip to content

Commit

Permalink
useAppFileHandling.getUrlForResource: add disposition option
Browse files Browse the repository at this point in the history
which can be either inline or attachment and can be used to define the purpose of the retrieved url.
Chrome allows us to use signed/downloadURLs for video playback although they send a Content-Disposition header, so we can just use a signed url and don't need to create a blob url for this.
We cannot embed PDFs in the same way, as they trigger downloads. So we need to create a blob url for those.

If you need a download url, it's fine (or even desired) for the response
to contain the Content-Disposition header.
  • Loading branch information
dschmidt committed Jul 28, 2022
1 parent 7df9bb7 commit f59928a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/web-app-pdf-viewer/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export default defineComponent({
try {
this.loading = true
this.resource = await this.getFileResource(fileContext.path)
this.url = await this.getUrlForResource(this.resource)
this.url = await this.getUrlForResource(this.resource, {
disposition: 'inline'
})
} catch (e) {
this.loadingError = true
console.error('Error fetching pdf', e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ export function useAppFileHandling({

const getUrlForResource = async (
{ webDavPath, downloadURL }: Resource,
options: { signUrlTimeout?: number } = {}
options: { disposition?: 'inline' | 'attachment', signUrlTimeout?: number } = {}
) => {
const signUrlTimeout = options.signUrlTimeout || 86400
const inlineDisposition = (options.disposition || 'attachment') === 'inline'

let signed = true
if (!downloadURL) {
if (!downloadURL && !inlineDisposition) {
// TODO: check whether we can fix the resource to always contain public-files in the webDavPath
let urlPath
if (unref(isPublicLinkContext)) {
Expand Down Expand Up @@ -66,7 +68,7 @@ export function useAppFileHandling({
// const combinedQuery = [queryStr, signedQuery].filter(Boolean).join('&')
// downloadURL = [url, combinedQuery].filter(Boolean).join('?')

if (!signed) {
if (!signed || inlineDisposition) {
const response = await getFileContents(webDavPath, {
responseType: 'blob'
})
Expand Down

0 comments on commit f59928a

Please sign in to comment.