У меня есть конечная точка API, которая работает с запросом PUT для обновления информации о пользователе, например аватара пользователя. Этот API построен на Django. В моем Frontend я использую NUXT для загрузки файла с помощью FilePond, я сделал следующее:
<template>
<section class="section">
<div class="container">
<file-pond
name="test"
ref="pond"
label-idle="Drop files here..."
v-bind:allow-multiple="true"
accepted-file-types="image/jpeg, image/png"
/>
<vs-button success @click='userinfo_put_avatar'>File upload data</vs-button>
</div>
</section>
</template>
<script>
import vueFilePond from 'vue-filepond';
import 'filepond/dist/filepond.min.css';
import 'filepond-plugin-image-preview/dist/filepond-plugin-image-preview.min.css';
import FilePondPluginFileValidateType from 'filepond-plugin-file-validate-type';
import FilePondPluginImagePreview from 'filepond-plugin-image-preview';
let FilePond = vueFilePond(FilePondPluginFileValidateType, FilePondPluginImagePreview);
export default {
components: {
FilePond,
},
methods: {
async userinfo_put_avatar() {
let file = this.$refs.pond.getFiles(0)
let fileupload = new FormData();
fileupload.append('avatar', file)
let config = {
headers: {
'Content-Type': 'multipart/form-data'
}
}
let data = await this.$axios.put('user-info/', fileupload, config);
},
}
};
</script>
У меня это очень хорошо работает. Но я хочу, чтобы функция Filepond показывала статус загрузки с вращающимся svg, когда в процессе загрузки и после завершения показывал зеленый статус.
![Progress Completed](https://i.stack.imgur.com/edtGY.png)
I tried using the pond.processFile(0)
but it doesnot upload the file.
I tried using the FilePond.setOptions()
but it gives me an error setOptions is not a function
. If this could work somehow.
I would be able to overwrite onaddfileprogress event using the following code from GITHUB ISSUE LINK
FilePond.setOptions({
instantUpload: true,
allowImagePreview: false,
server: {
url: '/images',
process: {
url: '/upload',
},
revert: '/revert',
restore: '/restore/',
load: '/load/',
},
onremovefile: function(error, file) {
if (file.serverId) {
let input = document.createElement('input');
input.type = 'hidden';
input.name = 'DeletedFilepondImages';
input.value = file.serverId;
uploadForm.appendChild(input);
}
},
onaddfilestart: function(file) {
console.log(`onaddfilestart`);
buttonForm.classList.add('filepondUpload');
buttonForm.setAttribute('disabled', 'true');
},
onaddfileprogress(file, progress) {
console.log(`onaddfileprogress`);
buttonForm.classList.remove('filepondUpload');
buttonForm.removeAttribute('disabled');
},
});
// get a reference to the input element
const filepondInput = document.querySelector(
'#filepondFileUploader input[type="file"]'
);
// create a FilePond instance at the input element location
const filepondObject = FilePond.create(filepondInput, {
maxFiles: 5,
acceptedFileTypes: ['image/*'],
labelIdle:
'<div class="image-upload__file-upload-content">Add images</div>',
files: filepondInitialFiles,
onprocessfiles() {
console.log('onprocessfiles');
buttonForm.classList.remove('filepondUpload');
buttonForm.removeAttribute('disabled');
},
});