LoginSignup
1
1

More than 5 years have passed since last update.

Firefoxでの自動ダウンロード

Posted at

問題

Microsoft Excelを自動的にダウンロードしたい時、以下のコードは普通だと思われます。

profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,";

「application/vnd.openxmlformats-officedocument.spreadsheetml.sheet」はMicrosoft ExcelのMIMEタイプです。しかし、相変わらず、「毎回確認する」というダイアログがでてきます。
キャプチャ.PNG

解決方法

ファイルのMIMEタイプは問題です。確かにExcelのMIMEタイプは正しいですが、Firefoxから見れば、ダウンロードファイルのMIMEタイプは違います。

Firefox -> ウェブ開発 -> ネットワーク(ctrl + shift + ) から見えます。
image.png

上の図から、Firefoxが見たダウンロードファイルのContent-Typeはapplication/force-downloadです。だから、以下のコードを試して、ファイルは自動的にダウンロードされました。

profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, "
                + "application/force-download");
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1