Adding upload validation

parent 6fc09975
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
:action="uploadUrl" :action="uploadUrl"
:on-remove="handleRemove" :on-remove="handleRemove"
:on-success="handleSuccess" :on-success="handleSuccess"
:file-list="fileList" :show-file-list="false"
:http-request="uploadFile" :http-request="uploadFile"
style="display: inline-block; margin-right: 10px;"> style="display: inline-block; margin-right: 10px;">
<el-button size="small" type="primary" style="padding: 11px 9px;">Upload File</el-button> <el-button size="small" type="primary" style="padding: 11px 9px;">Upload File</el-button>
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
}, },
data() { data() {
return { return {
fileList: [],
} }
}, },
computed: { computed: {
...@@ -52,7 +51,6 @@ ...@@ -52,7 +51,6 @@
methods: { methods: {
handleSuccess(response, file, fileList) { handleSuccess(response, file, fileList) {
this.$events.emit('fileWasUploaded', response); this.$events.emit('fileWasUploaded', response);
this.fileList = [];
}, },
uploadFile(event) { uploadFile(event) {
let data = new FormData(); let data = new FormData();
...@@ -60,8 +58,14 @@ ...@@ -60,8 +58,14 @@
data.append('file', event.file); data.append('file', event.file);
axios.post(route('api.media.store'), data) axios.post(route('api.media.store'), data)
.then(response => { .then(response => {
this.fileList = [];
this.$events.emit('fileWasUploaded', response); this.$events.emit('fileWasUploaded', response);
})
.catch(error => {
console.log(error.response.data);
this.$notify.error({
title: 'Error',
message: error.response.data.errors.file[0]
});
}); });
}, },
handleRemove() {}, handleRemove() {},
......
...@@ -9,8 +9,10 @@ class UploadMediaRequest extends FormRequest ...@@ -9,8 +9,10 @@ class UploadMediaRequest extends FormRequest
{ {
public function rules() public function rules()
{ {
$extensions = 'mimes:' . str_replace('.', '', config('asgard.media.config.allowed-types'));
return [ return [
'file' => ['required', new MaxFolderSizeRule()], 'file' => ['required', new MaxFolderSizeRule(), $extensions],
]; ];
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment