React-native-document-picker: how to set the type array for extensions

Created on 6 Sep 2019  路  10Comments  路  Source: rnmods/react-native-document-picker

I'm trying filter only for typical docs extensions:

 type: [
          '.pdf',
          '.docx', 
          'com.microsoft.word.docx', 
          'application/docx', 
          'com.microsoft.excel.xlsx', 
          'application/xlsx', 
          '.xlsx'
        ],

but I can't select them
imagen

FAQ extensions

Most helpful comment

Hi guys, sorry the late, this is how I was solved the issue

  1. You need install react-native-mime-types
  2. This is how I set the array:
    type: [ mime.lookup('docx'), mime.lookup('xlsx'), mime.lookup('doc'), mime.lookup('xls'), ],
    And works perfect

All 10 comments

I try too
type: [ ".docx application/docx com.microsoft.word.docx", ".doc application/doc com.microsoft.word.doc", ".xlsx application/xlsx com.microsoft.excel.xlsx", ".xls application/xls com.microsoft.excel.xls", DocumentPicker.types.pdf, ],

same issue. @franjorub Did you find any solution ?

@imbudhiraja yes I use react-native-mime-types and Every lookup funci贸n as array position

same issue. @franjorub Did you find any solution ? Example, please !!!

@franjorub can you please share a working example.

@franjorub I'm using this right now. but its not working. I'm using v3.2.4

const types = [
            DocumentPicker.types.pdf,
            'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
            'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
            'application/vnd.ms-powerpoint',
            'application/vnd.openxmlformats-officedocument.presentationml.presentation',
            'application/vnd.oasis.opendocument.text',
          ];

@douglas-cavalcante working code for .docx, .pptx, .xlsx, .pdfs.

const iosTypes = [
  'org.openxmlformats.wordprocessingml.document',
  'com.adobe.pdf',
  'org.openxmlformats.spreadsheetml.sheet',
  'org.openxmlformats.presentationml.presentation',
];

const androidTypes = [
  'application/msword',
  'application/pdf',
  'application/vnd.ms-excel',
  'application/vnd.ms-powerpoint',
];

Hope this works for you as well.

Hi guys, sorry the late, this is how I was solved the issue

  1. You need install react-native-mime-types
  2. This is how I set the array:
    type: [ mime.lookup('docx'), mime.lookup('xlsx'), mime.lookup('doc'), mime.lookup('xls'), ],
    And works perfect

2. type: [ mime.lookup('docx'), mime.lookup('xlsx'), mime.lookup('doc'), mime.lookup('xls'), ],

this will not work on iOS. Correct iOS type will be (as mentioned by @imbudhiraja )

const iosTypes = [
  'org.openxmlformats.wordprocessingml.document',
  'com.adobe.pdf',
  'org.openxmlformats.spreadsheetml.sheet',
  'org.openxmlformats.presentationml.presentation',
];

https://github.com/Elyx0/react-native-document-picker/issues/240#issuecomment-536447325 seems to be the correct way to do this, closing as answered.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JeremyBradshaw7 picture JeremyBradshaw7  路  6Comments

ashish-algorythma picture ashish-algorythma  路  7Comments

vsrinivas150283 picture vsrinivas150283  路  3Comments

Cchumi picture Cchumi  路  3Comments

MuneebJS picture MuneebJS  路  5Comments