Home > Net >  How to know the type of uploaded file in React app
How to know the type of uploaded file in React app

Time:08-06

I use the react app for uploading files to azure, but I want to know the type of file and then based on the type of file I want to upload to a specific container, e.g., if the user browses an image when user clicks on "upload" the file will upload to "container A", while if the file is video the file will upload to "container B". Therefore, I need to know what is the type of file.

CodePudding user response:

Here you can add below code to get file name and extension.

var files = event.target.files
var filename = files[0].name
var extension = files[0].type

In the type you will find the extension for eg: if it is jpeg image then,

extension = image/jpeg

or if pdf then,

extension = application/pdf
  • Related