#Wojtek
1 messages ยท Page 1 of 1 (latest)
Hi there!
Hey ๐
Give me a few minutes to look into this.
Thanks
Hey, stepping in here. Can you share the markup/JSX you're using?
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
Have you tried using the <Link /> component? https://stripe.com/docs/stripe-apps/components/link
Like I guess the idea is you'd generate the blob server-side and redirect to it that way
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
Why would that require a separate page?
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"
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
Otherwise, I'm not sure if this is supported currently. I'd recommend opening an issue over on GitHub: https://github.com/stripe/stripe-apps/issues