Skip to content

Commit 023c2f6

Browse files
committed
Fix #40: Stop using FileReader on selecting the update to upload
1 parent f396707 commit 023c2f6

File tree

1 file changed

+15
-33
lines changed

1 file changed

+15
-33
lines changed

src/components/Settings.vue

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,13 @@
3636
<h3 class="text-xs-left">Sistema </h3>
3737
<v-card>
3838
<div class="cardContent">
39-
4039
<v-select v-model="settings.progLevel" :items="blocklyToolboxItems" label="Livello Toolbox Blockly"></v-select>
4140
<!--<v-text-field v-model="settings.cbName" label="Nome CoderBot"></v-text-field>
4241
<br>-->
4342
<div v-for="(value, key, index) in cb.info">
4443
{{ key }}: <code>{{ value }}</code>
4544
</div>
46-
Vue app commit build: <code> {{ lastCommit }} </code>
45+
Vue app commit build: <code> {{ lastCommit }} </code>
4746
</div>
4847
</v-card>
4948
<br>
@@ -79,21 +78,17 @@
7978
<v-card>
8079
<div class="cardContent">
8180
<template v-if="updateStatus==1">
82-
Caricamento del file:
83-
<h3>{{ counter }} %</h3>
84-
<br>
85-
{{ updateStatusText }}
86-
87-
</template>
88-
<template v-if="updateStatus==2">
89-
90-
</template>
81+
Caricamento del file:
82+
<h3>{{ counter }} %</h3>
83+
<br>
84+
{{ updateStatusText }}
85+
</template>
86+
<template v-if="updateStatus==2">
87+
</template>
9188
<template v-if="updateStatus==0">
92-
9389
<v-text-field label="Seleziona il pacchetto di aggiornamento" @click='pickFile' v-model='fileName' prepend-icon='attach_file'></v-text-field>
9490
<input type="file" style="display: none" ref="file" @change="onFilePicked">
9591
<template v-if="this.fileObj"> Qualsiasi pacchetto di aggiornamento esistente verrà sovrascritto. CoderBot verrà riavviato per applicare l'aggiornamento.<br></template>
96-
9792
<v-btn v-if="this.fileObj" @click="upload" color="error">Conferma</v-btn>
9893
</template>
9994
</div>
@@ -252,36 +247,21 @@ export default {
252247
},
253248
onFilePicked(e) {
254249
const files = e.target.files
255-
if (files[0] !== undefined) {
256-
this.fileName = files[0].name
257-
if (this.fileName.lastIndexOf('.') <= 0) {
258-
return
259-
}
260-
const fr = new FileReader()
261-
fr.readAsDataURL(files[0])
262-
fr.addEventListener('load', function() {
263-
this.fileUrl = fr.result
264-
this.fileObj = files[0]
265-
}.bind(this))
266-
} else {
267-
this.fileName = ''
268-
this.fileObj = ''
269-
this.fileUrl = ''
270-
}
250+
this.fileName = files[0].name
251+
this.fileObj = files[0]
252+
this.formdata = new FormData();
253+
this.formdata.append('file_to_upload', files[0], files[0].name);
271254
},
272255
upload() {
273-
var formdata = new FormData();
274-
formdata.append('file_to_upload', this.fileObj)
275256
const config = {
276257
headers: { 'Content-Type': 'multipart/form-data' },
277258
onUploadProgress: progressEvent => {
278259
this.counter = Math.floor((progressEvent.loaded * 100) / progressEvent.total);
279-
280260
}
281261
}
282262
this.updateStatus = 1
283263
284-
this.$axios.post(this.CB + '/updateFromPackage', formdata, config).then(function(result) {
264+
this.$axios.post(this.CB + '/updateFromPackage', this.formdata, config).then(function(result) {
285265
this.uploadCompleted = true;
286266
this.uploadInProgress = false;
287267
console.dir(result.data);
@@ -503,6 +483,8 @@ export default {
503483
},
504484
data() {
505485
return {
486+
formdata: null,
487+
files: null,
506488
status: null,
507489
lastCommit: process.env.lastCommit,
508490
CB: process.env.CB_ENDPOINT + process.env.APIv2,

0 commit comments

Comments
 (0)