此函数将a转换
Blob为a
File,对我来说效果很好。
香草Javascript
function blobToFile(theBlob, fileName){ //A Blob() is almost a File() - it's just missing the two properties below which we will add theBlob.lastModifiedDate = new Date(); theBlob.name = fileName; return theBlob;}
Typescript (具有正确的键入)
public blobToFile = (theBlob: Blob, fileName:string): File => { var b: any = theBlob; //A Blob() is almost a File() - it's just missing the two properties below which we will add b.lastModifiedDate = new Date(); b.name = fileName; //Cast to a File() type return <File>theBlob;}
用法
var myBlob = new Blob();//do stuff here to give the blob some data...var myFile = blobToFile(myBlob, "my-image.png");
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)