如何创建一个从元素检索到的File对象的副本?
我尝试使用JSON.parse(JSON.stringify(file))
但是JSON.stringify(file)总是评估为"{}"
我尝试使用JSON.parse(JSON.stringify(file))
但是JSON.stringify(file)总是评估为"{}"
new File([blob], blob.name, { type: blob.type });
添加类型是很重要的。被接受的答案忽略了类型。
lastModified
。在这里查看构造函数参数:https://developer.mozilla.org/en-US/docs/Web/API/File/File。`new File([oldFile], oldFile.name, { type: oldFile.type, lastModified: oldFile.lastModified });` - undefinedvar newFileObject = {...file} OR Object.assign({}, ...file)
或使用-
JSON.parse(file.toString())
new File
创建一个新文件,但不确定是否有效。如果您有要解决的具体问题,请提供https://stackoverflow.com/help/mcve并更新问题。 - Estus Flasknew File([file], file.name)
运行良好。谢谢。 - displayName