Jump to content

Dowload Links Get Called 2x Via Android:Chrom


fivestringsurf

Recommended Posts

I have a php application that serves pdf downloads.  It works fine on all devices and browsers with one small but really annoying side-effect (edge-case for sure)

When I look at my download logs anytime the download is triggered from Chrome on Android it is called twice!  Bizarre behavior and I can't figure it out.

 

Some background:

 

The download is a pdf that get's created on the fly.

All requests get processed through my index.php controller.

 

I was serving the request with javascript via:

window.open('export?file=something_to_inform_the_controller');

Works great in all browsers and devices but android chrome triggers this twice.

 

So I got wise and though maybe a direct link would work better:

<a target="_blank" href="http://mysite.com/export?file=abc123" download="file.pdf">DL link</a>
or
<a target="_blank" href="http://mysite.com/export?file=abc123">DL link</a>
or
<a target="_self" href="http://mysite.com/export?file=abc123" download="file.pdf">DL link</a>
or
<a target="_self" href="http://mysite.com/export?file=abc123">DL link</a>

Nope, none of these flavors prevents android/chrome from double downloading.

 

Then I researched my php header settings and tried:

content-disposition: inline  vs.

content-disposition: attachment    with no success

 

Note, the download is logged when the controller processes the request for the download.  I have duplicated download events for all downloads on android/chrome.  It's strange that I have not found a solution online for this or maybe I'm overlooking something silly.

 

Any ideas?

It's because the browser initially requests the URL. Once it determines that it's content it can't handle and needs to be downloaded it passes the URL off to a separate download manager application which will then re-request the url and complete the download in the background.

 

This behavior is by design, there isn't anything you can do to make it issue only a single request.

@kicken,

 

excellent answer.  The reason I was most annoyed by this was when a user looks at their download history if they have been using an android device everything is doubled! 
I guest the solution is:

a) screw you android users (you're log activity is doubled for download requests)

b) don't log requests made by same user/link within <3 seconds of one another

 

Thanks again for your answer.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.