Javascript read MIME type of xls file always return empty

2,305 views
Skip to first unread message

simin lin

unread,
Sep 13, 2017, 2:03:48 AM9/13/17
to Chromium-discuss
Hi,

My chrome seems doesn't recognize the xls file. When I use file.type to get the mime type of xls file, it always return emtpy.
But it works for other files like xlsx, doc file.

Follow is my javascript code:
------------------------------------------------------------------------------------
function filechanged() {
        var form = document.getElementById('TForm')
        var file = form.getElementsByClassName('real-file-upload')[0].files[0];
        //alert(file.name)
        //alert(file.type)
        document.getElementById('FileName').textContent=file.name
        document.getElementById('FileType').textContent=file.type
      }
------------------------------------------------------------------------------------

Complete code is as follows:
------------------------------------------------------------------------------------

<!DOCTYPE html>
<html>
  <head>
    <title>test upload</title>

    <script>
      function filechanged() {
        var form = document.getElementById('TForm')
        var file = form.getElementsByClassName('real-file-upload')[0].files[0];
        //alert(file.name)
        //alert(file.type)
        document.getElementById('FileName').textContent=file.name
        document.getElementById('FileType').textContent=file.type
      }
    </script>
  </head>
  <body>
    <form id='TForm'>
      <input type='file' class='real-file-upload' onchange="filechanged()"/>
      <br />
    </form>
    <br />
    <label>File Name:</label><span id='FileName'></span>
    <br />
    <label>File type:</label><span id='FileType'></span>
  </body>
</html>

------------------------------------------------------------------------------------


How can I solve this problem?
And can I get the file type list supported by my Chrome?
However, I found that Chrome on some other mac do support the xls file. I wonder why the behavior is not the same. Can there any reason can cause the difference.

My mac version is Sierra 10.12.6, Chrome version is 61.0.3163.79.

Thanks very much

PhistucK

unread,
Sep 13, 2017, 2:42:11 AM9/13/17
to lin...@gmail.com, Chromium-discuss
If you double click on an XLS file, does it open it in a some spreadsheet application?

I reckon Chrome does not have a list of MIME types, perhaps other than the ones it can handle on its own (PDF, HTML, TXT, some media and image files and maybe some more).
I believe it draws the MIME types from the operating system, so if your operating system knows the correct MIME type for XLS, Chrome would show it as well. So check the settings of your operating system.


PhistucK

--
--
Chromium Discussion mailing list: chromium...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-discuss

---
You received this message because you are subscribed to the Google Groups "Chromium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discuss+unsubscribe@chromium.org.

simin lin

unread,
Sep 13, 2017, 6:46:38 AM9/13/17
to Chromium-discuss, lin...@gmail.com
Hi Phistuck,

Thank you very much for your reply.
My mac could not open xls file if I double click on xls file.
However, the Safari, Firfox web browser can return correct MIME type for xls file on the same mac.
If I set the default application to open the xls files, Chrome still cannot recognize the xls file.
I am trying to find the extension - mime map on mac right now.

在 2017年9月13日星期三 UTC+8下午2:42:11,PhistucK写道:


PhistucK

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discu...@chromium.org.

PhistucK

unread,
Sep 13, 2017, 9:28:14 AM9/13/17
to lin...@gmail.com, Chromium-discuss
If other browsers have hard coded list, this is an interoperability issue.
You can search crbug.com for an existing issue and star it. If you cannot find one, file a new issue using the "New issue" link on the same page.
Please, do not add a "+1" or "Me too" or "Confirmed" (or similar) comment. It just wastes the time of Chrome engineers and sends unnecessary e-mails to all of the people who starred the issue.

You can reply with a link to the found or created issue and might get triaged (and fixed) faster.

Thank you.



PhistucK

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discuss+unsubscribe@chromium.org.

simin lin

unread,
Sep 13, 2017, 10:49:15 PM9/13/17
to Chromium-discuss, lin...@gmail.com
Hi PhistucK,

Thank you very much for your suggestion.

I have found the same issue posted in crbug.com. The topic is here.

That topic helps.

Thanks again.

在 2017年9月13日星期三 UTC+8下午9:28:14,PhistucK写道:


PhistucK

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discu...@chromium.org.

PhistucK

unread,
Sep 14, 2017, 2:18:28 AM9/14/17
to simin lin, Chromium-discuss
In the issue, they state that Firefox behaves like Chrome, but in your case this is not true - so if I were you, I would file a new issue for it.


PhistucK

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discuss+unsubscribe@chromium.org.

Reply all
Reply to author
Forward
0 new messages