Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
156 views
in Technique[技术] by (71.8m points)

javascript - 如何从input = File更改javascript中文件的名称(How to change name of file in javascript from input=File)

I need to change the filename (not the file, just the metadata of the name) when uploading to a sharepoint site.(上传到共享点站点时,我需要更改文件名(而不是文件,只是名称的元数据)。)

I figured that it would be easy enough to change the html attribute in javascript rather than playing with Sharepoint backend.(我认为更改javascript中的html属性比使用Sharepoint后端要容易得多。) So that when I upload a file it changes the name of the file (not the data)(这样,当我上传文件时,它会更改文件名(而不是数据)) something like this:(像这样的东西:) function PreSaveAction(){ var file = document.GetElementById('fileupload1'); file.files[0].name='ChangedName.tmp' return true; } Is this impossible due to the nature of the locked input='file' attributes?(由于锁定的input ='file'属性的性质,这是否不可能?)   ask by michael translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

try this:(尝试这个:)

var element = document.GetElementById('fileupload1'); var file = element.files[0]; var blob = file.slice(0, file.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.(注意:这是针对图像类型的,您必须使用实际使用的类型来更改此类型。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...