I'm working with angular and ionic at the moment and I need to be able to upload and view a PDF file. So far I can choose the pdf file, however I'm having issues with upload it. This is my code thus far
<input type="file" name="file" id="file">
<ion-button onclick="uploadPDF()" name="submit">
Upload File
</ion-button>
<script>
function uploadPDF() {
let data = document.getElementById("file").files[0];
let entry = document.getElementById("file").files[0];
console.log('uploadPDF',entry,data)
fetch('uploads/' + encodeURIComponent(entry.name), {method:'PUT',body:data});
alert('your file has been uploaded');
location.reload();
};
</script>
When the upload file button is clicked a prompt should appear that says 'your file has been uploaded' however this does not occur