【问题标题】:Google Chrome MIME type for .csv file?.csv 文件的 Google Chrome MIME 类型?
【发布时间】:2018-04-10 18:00:40
【问题描述】:

谷歌浏览器是否支持 csv MIME 类型?我的 mime.types (Nginx) 文件中有以下条目(这些只是 csv 相关条目):

types {
  text/csv                              csv;
  text/comma-separated-values           csv;
  text/anytext                          csv;
  application/csv                       csv;
  application/csv+xml                   csv;

}

这是我的 nginx.conf 文件:

    user  nginx;
    worker_processes  1;

    error_log  /var/log/nginx/error.log warn;
    pid        /var/run/nginx.pid;


    events {
      worker_connections  1024;
    }


    http {
      include       /etc/nginx/mime.types;
      default_type  application/octet-stream;

      gzip_types text/plain text/xml text/css
                   text/comma-separated-values
                   text/javascript application/x-javascript
                   application/atom+xml;

      log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

      access_log  /var/log/nginx/access.log  main;

      sendfile        off;
      #tcp_nopush     on;
      keepalive_timeout  65;
      #gzip  on;
      include /etc/nginx/conf.d/*.conf;
}

但 Chrome 不会喜欢它!不过在 Safari 上没问题!

是否有特定于 Chrome 的 csv 支持?

谢谢

【问题讨论】:

  • 打开 csv url 并查看 chrome 中的网络检查器,您的服务器返回的内容类型标头是什么?
  • 应用程序/json; charset=utf-8
  • @AlexK。我回答了这个问题,以为我会让你知道。还是谢谢

标签: csv google-chrome nginx browser mime-types


【解决方案1】:

我通过添加解决了这个问题:

add_header  Content-Type    text/csv;

到我定义我的特定位置的 nginx webapp.conf 文件:

location /ingressfile {
    access_log /var/log/nginx/ingressfile.log main;

    set   $module   company.api;
    set   $app      app;
    uwsgi_pass      restapi;
    uwsgi_intercept_errors on;
    # add support for csv files
    add_header  Content-Type    text/csv;

    # Use this I'm-a-teapot code to redirect to static file
    error_page 418 = @ingressfile;
}

希望这可以帮助遇到同样问题的人!

【讨论】:

    猜你喜欢
    • 2010-10-25
    • 2013-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-23
    • 1970-01-01
    • 2013-05-24
    相关资源
    最近更新 更多