JSFiddle - React, Tailwind, and code Playground

VUE detect file type

by abernov

HTML

<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>


<div id="app">
 <input v-model="uri"></input>
 <button @click="getMimeType">
   GetMimeType
 </button> 
 <div  v-html="logTxt">
 </div>
</div>

JavaScript

new Vue({
  el: '#app',
  data: {
      logTxt: '',
      uri1: 'http://keenvision.ru/wp-content/themes/keenvision/img/keenvision-logo.png',
      uri: 'https://httpbin.org/ip'
  },
  mounted() {
  	this.log('ccc');
  },
  methods: {
  	log(txt) {
    	this.logTxt += txt + '<br>';
    },
    getMimeType() {
    	this.logTxt = '';
      
      this.log('0')
      this.$http.get(this.uri1).then ( response => {
       this.log('1')
/*   		 response.on('readable', () => {
        const chunk = response.read(fileType.minimumBytes);
        response.destroy();
        this.log(fileType(chunk));
        //=> {ext: 'gif', mime: 'image/gif'}
    	 }); */
		  },
      err =>{
       console.log('Err=%o', err)
       this.log('err.status=' + err.status)      
      });
    }
  }
});