Obtain the content of the INPULAR2 to get the content of the file upload file

Recently used Angular2, you need to have a function of uploading files, but don’t want to use libraries, so use the original Input File tag.

    then want to get uploaded content, so I think a stupid method first, first Get this INPUT label by ID, then get the contents of the upload 

const uploadsfile = document.GtelementByid (Name) .files [0];
   The result was wrong. Then see the prompt saying that HTMLELEMENT does not have a Files method. So I found the type of Files attribute in ES6, which is the htmlinputelement type. So it is forced that convert it into this type. 
const uploadsfile =

Document.getlementByid (Name) .files [0];

  No, finally changed to the first conversion type and then call attributes.   
const uploadsfile = Document.GtelementByid (Name); const file = uploadsfile.files [0];

After discovered this way, it seems stupid, so I changed a method, with the $ Event in Angular2 to get the input content, including the selected file.
    

The selected file is in Event.Target.Files

  Private getupload (Obj, e) {if (e.target.files [0]) {const file = e.target.files [0]; Obj.file = file;}}   
can then put it in Formdata

const formdata = new formData (); FormData.Append (‘file’, this.upload.file);
   
Finally empty selection upload The content can be used

Document.QuerySelector (selectorname); UPLOAD.VALUE = NULL;
   
I don’t know if there is a better way, welcome to discuss and correct.

The above is all the content of this article, I hope to help everyone, I hope everyone will support Tumi Clouds.

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment