Last active
May 17, 2018 09:20
-
-
Save DespertaWeb/d6249b109a8fa39b14dade760537d9b0 to your computer and use it in GitHub Desktop.
File load and Display
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
axios({ | |
url: `${config.BASE}/download/${this.section.urlSingular}_50.pdf`, | |
method: 'GET', | |
headers: LocalStorage.get('inv.headers'), | |
responseType: 'blob' | |
}) | |
.then((response) => { | |
this.urlPdf = URL.createObjectURL(response.data) | |
}) | |
.catch((error) => { | |
console.log('ERROR ', error) | |
}) |
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 id="file-input" type="file" onchange="onUpload(this)" /> | |
<div id="display-pdf"></div> |
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
function onUpload(input) { | |
let originalFile = input.files[0]; | |
let reader = new FileReader(); | |
reader.readAsDataURL(originalFile); | |
reader.onload = () => { | |
let json = JSON.stringify({ dataURL: reader.result }); | |
// View the file | |
let fileURL = JSON.parse(json).dataURL; | |
$("#display-pdf").empty(); | |
$("#display-pdf").append(`<object data="${fileURL}" | |
type="application/pdf" width="400px" height="200px"> | |
</object>`); | |
// View the original file | |
let originalFileURL = URL.createObjectURL(originalFile); | |
$("#display-pdf").append(`<object data="${originalFileURL}" | |
type="application/pdf" width="400px" height="200px"> | |
</object>`) | |
.onload(() => { | |
URL.revokeObjectURL(originalFileURL); | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment