force file to download and not open

  1. 3 weeks ago

    Russ L

    Jan 29 Pre-Release Testers, Xojo Pro

    HI,

    I'm sure i've asked this before but i cant seem to find the answer.

    I want the user to download a pdf, but i dont want it to open it just to download it
    is that possible. it always seems to open the pdf in the current tab .

    @Russ L It seemed to work! Now instead of opening in the same tab it downloads and opens in adobe on the desktop. I think that is something in Windows 10 though. Perhaps I’m wrong.

    Windows 10 or the browser. Safari, for example, has an "open safe files after downloading" preference.

  2. Tim S

    Jan 29 Canterbury, UK

    Do you have control over the headers that the server writes? I.e., the machine where the pdf sits?

  3. Paul L

    Jan 29 Xojo Inc http://docs.xojo.com

    How did you implement this? Is WebFile.ForceDownload = True for the file?

    https://docs.xojo.com/WebFile

  4. David C

    Jan 30 Pre-Release Testers, Xojo Pro Derby, ITM

    Sometimes whether it downloads or not depends on the whim of the browser. If you zip any file first, it will force it to download too. Not recommended for large PDFs (due to time to compress), though it can be done, as they are already compressed.

  5. Christian S

    Jan 30 Pre-Release Testers, Xojo Pro, XDC Speakers Germany

    ForceDownload changes download to tell browser to save it as file.
    But if browser knows file extension, it may decide otherwise and prefer to show inline.

  6. 2 weeks ago

    Russ L

    Jan 31 Pre-Release Testers, Xojo Pro

    i think David and Christian are correct - it doesn't matter what my webapp does, the browser will decide. I even changed my settings in chrome to force pdf downloads and they display in the browser!

    i am displaying a listbox of invoices and the user clicks on the ones they want and then clicks download pdf. problem is once the browser displays the pdf, its in the same tab and then the back button moves the user back to my login page.

    i cant think of a way round this, they just want to click on the row ( 20 or 30 times) and download the pdf for later processing.
    on other sites than mine though, they want to display the pdfs of course.

    its such a pain!

  7. Russ L

    Jan 31 Pre-Release Testers, Xojo Pro

    @Paul L How did you implement this? Is WebFile.ForceDownload = True for the file?

    https://docs.xojo.com/WebFile

    yes, its set to download= true, chrome overrides that though. makes it very hard work for the user to download 20 pdf's :-(

  8. Daniel T

    Jan 31 Pre-Release Testers, Xojo Pro

    What happens when you use a clean install of Chrome with no plugins? I ask because a quick test on my machine shows that Chrome downloads the PDF when I set WebFile.ForceDownload to True.

  9. Russ L

    Jan 31 Pre-Release Testers, Xojo Pro
    Edited 2 weeks ago

    @Daniel T What happens when you use a clean install of Chrome with no plugins? I ask because a quick test on my machine shows that Chrome downloads the PDF when I set WebFile.ForceDownload to True.

    Interesting. I will have to test. Although I suspect that I’m trying to push water uphill.

    Perhaps the ‘problem’ is that once the user has followed the url to the pdf , the back button needs to return them to where they were. Perhaps it’s just a question of maintaining state. Then the user can do what they like with the browser settings for pdf.

  10. Christian S

    Jan 31 Pre-Release Testers, Xojo Pro, XDC Speakers Germany

    forcedownload will do three things:

    mime type changed to "application/octet-stream"
    Content-Disposition set to "attachment; filename= with the filename you gave.
    Content-Description set to "File Transfer"

    The browser is Kindly asked to download with the Content-Disposition as well with the mime type.
    But due to a lot of bad configured web servers, they may show something with .pdf file extensions.

  11. Peter M

    Jan 31 Pre-Release Testers, Xojo Pro Copenhagen

    Have you tried to download with a dummy name, and then rename?

    Just a suggestion!

  12. David C

    Feb 1 Pre-Release Testers, Xojo Pro Derby, ITM

    @Peter Maelig;r Have you tried to download with a dummy name, and then rename?

    Just a suggestion!

    Once the browser has downloaded the dummy file, you cannot access the file system to rename it — how are you suggesting the renaming happens?

  13. Christian S

    Feb 1 Pre-Release Testers, Xojo Pro, XDC Speakers Germany

    ForceDownload = true should do it.
    If not, you can zip file on server and deliver zip file and hope for auto expand.
    You can even do different behavior for different browsers.

  14. Russ L

    Feb 1 Pre-Release Testers, Xojo Pro

    forcedownload is definitely true.

    the user doesn't want to unzip them, they are trying to speed up the workflow.

    I'm currently on 2017r1.1 - is it possible that this might be something that has changed since then?

    i turned off the chrome extension jspdf and now it opens in adobe!

    i don't have the adobe extension included so it might be the desktop app. this is getting weirder!

  15. Peter M

    Feb 1 Pre-Release Testers, Xojo Pro Copenhagen

    @David C Once the browser has downloaded the dummy file, you cannot access the file system to rename it — how are you suggesting the renaming happens?

    Maybe; https://www.monkeybreadsoftware.net/files-macfileoperationmbs-shared-method.shtml#1

  16. Daniel T

    Feb 1 Pre-Release Testers, Xojo Pro
    Edited 2 weeks ago

    @Russ L i turned off the chrome extension jspdf and now it opens in adobe!

    i don't have the adobe extension included so it might be the desktop app. this is getting weirder!

    I added PDF JS to Chrome. After doing so it ignored ForceDownload and displayed the PDF in the browser. So that's the culprit.

    As to Adobe Acrobat opening the file: browsers are commonly configured to 'open safe files.' I personally hate this behavior, but it's something you have no control over from a web site. If a user wants to just click rows and download the PDFs they must disable PDF Viewer extensions and any options to process files after completion.

    Edit: maybe the users would be more open to zip downloads if you had them select all the PDFs they want, then sent them as one zip file. They would only have to unzip the one file. Just a thought because zip files are the only way I can see around this.

  17. Greg O

    Feb 3 Xojo Inc

    Something else to try...

    After setting up the webfile, set it’s Mime Type to:

    application/octet-stream
  18. Christian S

    Feb 3 Pre-Release Testers, Xojo Pro, XDC Speakers Germany

    But that is what forcedownload does already!?

  19. Daniel T

    Feb 3 Pre-Release Testers, Xojo Pro

    @ChristianSchmitz But that is what forcedownload does already!?

    I would have thought the same.

  20. Russ L

    Feb 3 Pre-Release Testers, Xojo Pro

    It seemed to work! Now instead of opening in the same tab it downloads and opens in adobe on the desktop. I think that is something in Windows 10 though. Perhaps I’m wrong.

  21. Newer ›

or Sign Up to reply!