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

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

    I Suggest to use the blob api, I've found the same problem and I solved like that:

    var html = whatever on svg 
    var fileName = "myfile.svg";
    var blob = new Blob([html], {type: 'image/svg'});
    blob.lastModifiedDate = new Date();
    // var blobAttrs = {type: "image/svg"};
    // var file = new File([html], fileName, blobAttrs);
    var formData = new FormData();
    formData.append("file",blob,fileName);
    

    It is not a "file", but you can use it like it was.

提交回复
热议问题