#Wojtek

1 messages ยท Page 1 of 1 (latest)

hollow notchBOT
inner horizon
#

Hi there!

sand abyss
#

Hey ๐Ÿ˜„

inner horizon
#

Give me a few minutes to look into this.

sand abyss
#

Thanks

woven gust
#

Hey, stepping in here. Can you share the markup/JSX you're using?

sand abyss
#

Hey, sorry I didn't see the notification

#
const downloadDocument = async (location: string, fileName: string) => {
    const response = await fetch(location, {
      method: 'GET',
      headers: {
        'Content-Type': getContentType(fileName),
        authorization: authorization,
      } as HeadersInit,
    })
    const blob = await response.blob()
    const url = URL.createObjectURL(new Blob([blob]))
    const link = document.createElement('a')
    link.href = url
    link.setAttribute('download', fileName)
    // Append to html link element page
    document.body.appendChild(link)
    // Start download
    link.click()
    // Clean up and remove the link
    if (link.parentNode) {
      link.parentNode.removeChild(link)
    }
  }
#

I use this to download in my other web apps

#

And here I trigger that on click of a button, so JSX doesn't help here I guess ๐Ÿ˜„

#

I need to make a GET request with auth header that returns the content of the file

#

I can't just put a link as there is no way to add authorization header then

#

In the iframe I can't trigger the link.click() because of the security reasons

#

I wonder if I'm the first person who has this issue

woven gust
#

Like I guess the idea is you'd generate the blob server-side and redirect to it that way

sand abyss
#

That would require a different flow right? A separate page which triggers a download

#

I'd need to move the whole download logic to that separate page. For now I'm interested in triggering the download directly from the stripe app

woven gust
#

Why would that require a separate page?

sand abyss
#

If I just open a blob via link I'll get the content of the blob, it won't trigger the download

#

This is what happens when I create a link to a blob as target="_blank"

woven gust
#

No, I mean generate the blob server-side and redirect to it there

#

The button is essentially a fetch call to your endpoint and that's it

hollow notchBOT