Gentlemen

I started writing the first project in TypeScript some time ago. A project is a single page application, something like ToDo List.

Now I have done that the items in the sheet are added. But I want to download files (for example, images and text files that will be processed when loading)

I can not find any example of upload file to TypeScript. I found an example that does a lot more - it adds several files, it shows the progress of the apload and some statistics - but it’s complicated and I couldn’t figure it out. ( Complicated example of file upload )

Does anyone help with the same, but a simple example?

Thank.

    1 answer 1

    Depending on how you want to load the file: HTML5 file upload or form. I see no problem translating the code of these methods from JS (where there are many examples) to Typescript.

    • I want to write in HTML something like attach a file: <input id = "file1" type = "file" /> Then I’m below my button and hang up a function on its handler that is already in TypeScript. This all turns out without problems. But then - the problem: In TouriSkszze - the code I do something like var file1Field = document.getElementById ("file1"); This is the field that was intended to enter the file. and how to get the file from it? - SH
    • Do I need to reload the page or download ajax? - tcpack4
    • I'm going to do everything with Ajax, and I even understand something like: var formData = new FormData (); formData.append ("eid", a.Eid); formData.append ("textField", txt); formData.append ("file1", files [0]); var xhr = new XMLHttpRequest (); try {xhr.open ('POST', "AcceptForm.aspx", false); xhr.send (formData); } catch (error) {var ec = error.code; var rt = xhr.responseText; return; } That's just how to create an array of files [] or at least click on its element files [0] - I don’t know :-( - SH
    • I read an example on JS, in it getting the file goes like this: var selectedFile = document.getElementById ('input'). Files [0]; But I cannot directly translate this construct into TypeScript. The last call in the chain (.file [0]) - does not work :-( - SH
    • one
      here you need to directly specify the type that is expected after receipt by ID. let input = <HTMLInputElement> document.getElementById ('input'); input.files [0] read here how type assertion works. basarat.gitbooks.io/typescript/content/docs/types/… - tcpack4