amin
amin

Reputation: 123

How to know the type of uploaded file in React app

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.

Upvotes: 0

Views: 575

Answers (1)

heyitsvajid
heyitsvajid

Reputation: 1121

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

Upvotes: 2

Related Questions