Skip to content

Instantly share code, notes, and snippets.

@DespertaWeb
Last active May 17, 2018 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DespertaWeb/d6249b109a8fa39b14dade760537d9b0 to your computer and use it in GitHub Desktop.
Save DespertaWeb/d6249b109a8fa39b14dade760537d9b0 to your computer and use it in GitHub Desktop.
File load and Display
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)
})
<input id="file-input" type="file" onchange="onUpload(this)" />
<div id="display-pdf"></div>
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