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

Incorrect filename of downloaded file #734

Closed
akoval opened this Issue May 10, 2018 · 8 comments

Comments

Projects
None yet
3 participants
@akoval
Copy link

akoval commented May 10, 2018

Incorrect filename after downloading

Filename of the downloaded file is the same as href. So
href="myfileblabla.txt?sessioncookie=12345%2323
will produce file with name "myfileblabla.txt?sessioncookie=12345%2323"

Details

Need to extract filename from href until ?

Tell us about your environment

  • Selenide Version: 4.11.4
  • Chrome\Firefox\IE Version: 66
  • OS Version: Windows
@akoval

This comment has been minimized.

Copy link

akoval commented May 10, 2018

this issue can raise issues on Windows. Not all filenames are valid on Windows OS

@rosolko

This comment has been minimized.

Copy link
Collaborator

rosolko commented May 10, 2018

@akoval Can you please specify what type on fileDownload do you use in Configuration?

@akoval

This comment has been minimized.

Copy link

akoval commented May 10, 2018

@rosolko I use only that

Configuration.browser = "chrome"; Configuration.timeout = 10000;

Should I setup smth specific?

@rosolko

This comment has been minimized.

Copy link
Collaborator

rosolko commented May 10, 2018

@akoval Got it. No, you don't. Thanks for information.

@rosolko rosolko added bug 🐛 and removed bug 🐛 labels May 10, 2018

@rosolko rosolko added this to the 4.11.5 milestone May 10, 2018

@rosolko rosolko self-assigned this May 10, 2018

@rosolko rosolko closed this in #735 May 10, 2018

rosolko added a commit that referenced this issue May 10, 2018

Add '?' symbol to filename pattern to avoid url query string paramete…
…rs. (#735)

* Add '?' symbol to filename pattern to avoid url query string parameters.
Fix #734 issue.
* Add tests for filename query string params.
@akoval

This comment has been minimized.

Copy link

akoval commented Jul 23, 2018

@rosolko problem is still actual.

I found the place where it should construct filename.

protected String getFileName(String fileToDownloadLocation, HttpResponse response) throws MalformedURLException {
    for (Header header : response.getAllHeaders()) {
      Optional<String> fileName = httpHelper.getFileNameFromContentDisposition(header.getName(), header.getValue());
      if (fileName.isPresent()) {
        return fileName.get();
      }
    }

    log.info("Cannot extract file name from http headers. Found headers: ");
    for (Header header : response.getAllHeaders()) {
      log.info(header.getName() + '=' + header.getValue());
    }

    return new URL(fileToDownloadLocation).getFile().replaceFirst("[/\\\\]", "");
  }

I see following message in the logs:
"Cannot extract file name from http headers. Found headers: "

So looks like your fix is working only for content-disposition case

@rosolko

This comment has been minimized.

Copy link
Collaborator

rosolko commented Jul 23, 2018

@akoval Understood.
Please, provide a full example with page and file that's can be used as proof of problem.
So I will be able to reproduce this issue on my local environment.
Thanks.

@akoval

This comment has been minimized.

Copy link

akoval commented Jul 24, 2018

demo.zip

I uploaded demo project that contains 1 html page with link to the file with some query params.

Open http://localhost:8080/1.html. Link is http://localhost:8080/test.txt?www=1111&rrr=2222

Test:

Configuration.browser = "chrome";
Configuration.timeout = 10000;
open("http://localhost:8080/1.html");
$("#link").download();

When I click the link I have no any Content-Disposition header

@rosolko rosolko referenced this issue Jul 25, 2018

Merged

Final fix for issue #734 #768

2 of 2 tasks complete

asolntsev added a commit that referenced this issue Jul 26, 2018

@asolntsev

This comment has been minimized.

Copy link
Contributor

asolntsev commented Jul 26, 2018

@akoval @rosolko Thank you. Will be released in Selenide 4.12.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment