如何从input = File更改javascript中的文件名 [英] How to change name of file in javascript from input=File
本文介绍了如何从input = File更改javascript中的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
上传到sharepoint网站时,我需要更改文件名(不是文件,只是名称的元数据)。
I need to change the filename (not the file, just the metadata of the name) when uploading to a sharepoint site.
我认为这很容易足以在javascript中更改html属性而不是使用Sharepoint后端。因此,当我上传文件时,它会更改文件的名称(而不是数据)
I figured that it would be easy enough to change the html attribute in javascript rather than playing with Sharepoint backend. So that when I upload a file it changes the name of the file (not the data)
这样的内容:
function PreSaveAction(){
var file = document.GetElementById('fileupload1');
file.files[0].name='ChangedName.tmp'
return true;
}
由于锁定input ='file'属性的性质,这是不可能的?
Is this impossible due to the nature of the locked input='file' attributes?
推荐答案
试试这个:
var file = document.GetElementById('fileupload1');
var blob = file.files[0].slice(0, file.files[0].size, 'image/png');
newFile = new File([blob], 'name.png', {type: 'image/png'});
注意:
这是图像类型,您必须更改此类型的类型你实际上在使用。
note: this is for a image type, you have to change this type with type you're actually using.
这篇关于如何从input = File更改javascript中的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文