This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let foo = 'bar' | |
/** | |
Don't worry about the code block, it will be saved as a gist with right language format, and auto embed to your post. | |
**/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Hello1 | |
{ | |
public static void Main() | |
{ | |
- System.Console.WriteLine("Hello, World!"); | |
+ System.Console.WriteLine("Rock all night long!"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let a = "asdf"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const inputElement = document.getElementById("inputElement") | |
inputElement.onchange = (e) => { | |
const file = inputElement.files[0] | |
if (!file) return | |
const reader = new FileReader() | |
reader.onload = (e) => { | |
// e.target points to the reader | |
const textContent = e.target.result | |
console.log(`The content of ${file.name} is ${textContent}`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get a reference to the inputElement in any way you choose | |
const inputElement = document.getElementById("inputElement") | |
// get the value once | |
inputElement.files[0] | |
// get the value every time the user selects a new file | |
inputElement.addEventListener("change", (e) => { | |
// e.target points to the input element | |
const selectedFile = e.target.files[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const file = new File([blob], "fileName", {type: blob.type}) | |
const blob = new Blob([file], {type: file.type}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using promise.then() | |
file.text().then(text => /* do something */); | |
// using async/await | |
const text = await file.text(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const reader = new FileReader() | |
// readyState is 0, result is null | |
reader.onload = () => { | |
// readyState is 2, result is the file's content | |
} | |
reader.onerror = () => { | |
// readyState is 2, result is null | |
} | |
// readyState is 0, result is null | |
reader.readAsText(file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// assuming that processImage and processText are functions | |
if (file.type.startsWith('image/')) { | |
reader.onload = processImage | |
reader.readAsDataURL(file) | |
} else if (file.type.startsWith('text/')) { | |
reader.onload = processText | |
reader.readAsText(file) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input type="file" id="inputElement" /> |
OlderNewer