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

后端 未结 4 1763
刺人心
刺人心 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:25

    If you can use ES6 classes:

    class CustomFile extends Blob
    {
        constructor(blobParts, filename, options) {
            super(blobParts, options);
            this.name = filename || "";
            if(options) {
              this.lastModified = options.lastModified;
            }
        }
    
        lastModified = 0;
        name = "";
    }
    const blob = new Blob();
    const fileObject = new CustomFile([blob],"myfile");
    
    console.log(fileObject);

提交回复
热议问题