Is there an alternative for File() constructor for Safari and IE?

后端 未结 4 1762
刺人心
刺人心 2020-12-30 04:05

I am using the File() constructor for creating file object for uploading a blob file to the server. The following code works fine for Chrome, but fails for Safari and Intern

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-30 04:35

    There is a File ponyfill on npm which works with modern module imports. This makes usage simple but you do need to import it in every module where you use new File().

    import File from '@tanker/file-ponyfill';
    
    const myFile = new File(['somefiledata'], 'example.txt', { type: 'text/plain'});
    

提交回复
热议问题