Therian
Therian

Reputation: 93

What component to use for file upload?

I know this is a simple question but I just cant find it anywhere. I am creating app in react native and I need to upload users image (which I found you can do) but also just any files user wants.

Thing is, all I've found was tutorials how to upload images not files. I have no trouble sending data through REST API, all I need is some component that actually allows user to upload file. In react webpage you can just create classic input with type file, but not in react-native.

TLDR, what is react-native equivalent of:

<input
type="file" onChange={e => {
//function that processes files here
}}/>

Thanks for any answer in advance...

Upvotes: 1

Views: 1683

Answers (1)

Sathvik Nasani
Sathvik Nasani

Reputation: 227

hi @therian you can use react-native-document-picker like

import { DocumentPicker, DocumentPickerUtil } from 'react-native-document-picker';

using above package

// iPhone/Android
DocumentPicker.show({
  filetype: [DocumentPickerUtil.allFiles()],
},(error,res) => {
  // Android
  console.log(
     res.uri,
     res.type, // mime type
     res.fileName,
     res.fileSize
  );
});

by using above package the user can manually select the pdf file, images, all type of files the user whant.

if you whant to select only pdf files or images or audio files that also you can do.

Upvotes: 3

Related Questions