javascript - How to modify a File's type property? -
so no surprise browsers have different list of recognised mime types.
see embedded screenshot of pen.
all browsers except chrome have supplied file object type set audio/mpeg.
in case of chrome type empty string ''.
this makes client side validation of file types accepted pain deal with. (especially in context when allowed quite 'open' video/* or audio/* files.
i want polyfill type on file object when comes blank in browsers. allow me more consistently validate whether file of allowed types.
however, type attribute on file read-only. cannot modified.
is there way bypass limitation?
such creating copy of file object , overriding type?
i ended solving following.
let polyfillmimetype (let = 0; < $newfiles.length; i++) { if (!$newfiles[i].type) { polyfillmimetype = mimetype.lookup($newfiles[i].name) $newfiles[i] = new window.file([$newfiles[i]], $newfiles[i].name, { type: polyfillmimetype }) } } 
Comments
Post a Comment