Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Is the text/csv mime type supported by SmartGWT's FileItem?

    I am using FileItem.setAccept() to set the proper file types I want to allow in an upload file operation. Using FileItem.setAccept("text/plain") works as expected, allowing me to see only .txt files:
    Click image for larger version

Name:	MimeTXT.png
Views:	194
Size:	35.8 KB
ID:	237849


    But when I use FileItem.setAccept("text/csv") or FileItem.setAccept("text/csv,text/plain"), the file chooser shows no .csv files (only .txt files in the second case - which is the same result I get when only using "text/plain").

    This is the whole list of files that is available at that location:
    Click image for larger version

Name:	AvailableFiles.png
Views:	263
Size:	36.4 KB
ID:	237850


    Is text/csv not supported by SmartGWT?

    Thanks

    I am using SmartgGWT 6.0p 2016-05-11.

    #2
    You didn't mention what browser, but basically, we are taking the value you supply and putting it right into the native "accept" attribute. If this doesn't behave as expected, it's a browser issue, and you could Google to see if some browsers will reject specific mime types but understand others.

    Comment


      #3
      It's Chrome Version 50.0.2661.94 m. I Googled around, and found out that I needed to use just .csv as the mime type (for Chrome at least). These are my final code excerpts that got it working:

      Code:
      private static final String MIME_TYPES = "application/csv," + 
                                                   "text/csv," +
                                                   "text/plain," +
                                                   "text/comma-separated-values," +
                                                   ".csv"; 
      ...
      FileItem file = new FileItem("fileLoadField);
      file.setAccept(MIME_TYPES);
      If you come looking at this thread, please know that for Chrome, ".csv" is sufficient. The other types are there to support text files and csv in different browsers.

      Thanks Isomorphic for pointing me in the right direction.

      Comment


        #4
        Thanks for posting your solution!

        May we just comment that we are quite surprised that Chrome requires ".csv" in particular. That's not even a correctly formatted mime type. Chrome usually does better on adherence to standards.

        Comment

        Working...
        X