Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to save content of data url to file #347

Open
fhoeben opened this issue Sep 22, 2020 · 6 comments
Open

Add support to save content of data url to file #347

fhoeben opened this issue Sep 22, 2020 · 6 comments

Comments

@fhoeben
Copy link
Owner

fhoeben commented Sep 22, 2020

Currently BrowserTest supports downloading the target of a link or source of an image to file. But content does not always have to be a separate resource that can be retrieved on its own (by http get). It can also be included in the web page as a so called data url.

JsonHttpTest already supports saving of binaries encoded in that format to file. It would be great if BrowserTest's download functionality would also (transparently) support this.
This could be used for images, but also for PDFs embedded in an iframe (where the PDF content is the iframe's src) see #346

This is probably quite easy to implement; in downloadContentFrom() just check whether the URL is a data-url (using the already existing DataUrlHelper) and if so save the content directly from the URLs content instead of doing a http GET to retrieve the file.
Of course no filename would be known, so one has to be automatically generated. If the data URL contains a content type this should be used to determine the extension of the file.

@Taxanas
Copy link
Contributor

Taxanas commented Sep 23, 2020

Woud be nice to have ability to use downloadContentFrom() not only by http GET, but also by http POST.
Example: zip file is downloaded according requested form data by POST.

@Taxanas
Copy link
Contributor

Taxanas commented Sep 23, 2020

And additionally, having posibility to set headers :)

@fhoeben
Copy link
Owner Author

fhoeben commented Sep 23, 2020

@Taxanas how would such a post work? Which data (and headers should be posted)?
I believe that such a download would normally be triggered by JavaScript; how does BrowserTest know what to send?

I believe for these POST downloads, the currently available alternative, of using HttpTest is the only viable option.

@Taxanas
Copy link
Contributor

Taxanas commented Oct 12, 2020

@fhoeben , sorry, responding just now:
i believe headers could be optional. In my case, headers must contain security token.

I believe this should be handled not in BrowserTest, but in HttpTest class.

Such post should work as get file from just instead of GET, use POST method.

Either way, i managed to make a workaround already to this case in headless chrome on remote grid, so its not so relevant anymore.

@roydekleijn
Copy link
Contributor

roydekleijn commented Apr 13, 2021

@fhoeben

@Taxanas how would such a post work? Which data (and headers should be posted)?
I believe that such a download would normally be triggered by JavaScript; how does BrowserTest know what to send?

I believe for these POST downloads, the currently available alternative, of using HttpTest is the only viable option.

How does such POST (which automatically downloads the content) look like? In my case I need to perform a POST, then a PDF is returned. When I create a new file (with FileFixture) the document content is somehow corrupted and eventually it doesn't display the PDF (just a blank document)

@fhoeben
Copy link
Owner Author

fhoeben commented Apr 13, 2021

@roydekleijn if there is a problem POSTing using HttpTest and then saving to file, please create a separate issue. What you appear to be describing does not seem to be related to this (original) issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants