I managed to successfully upload files from my frontend using Vue to Laravel backend.
The upload functionality was implemented using this code snippet:
addPost() {
axios.post('api/submitPropertyPhoto?token=' + this.token, this.postFormData)
.then(r => {
console.log(r)
})
.catch(e => {
console.log(e)
}
},
uploadFieldChange(e) {
for(let key in e.target.files) {
this.postFormData.append('images[]', e.target.files[key])
}
}
However, when I attempted to retrieve the file using the normal Laravel request file helper method, it returned nothing. Strangely, when I used dd($request->files)
, it provided the following details:
FileBag {#68
#parameters: array:1 [
"images" => array:1 [
0 => array:1 [
"name" => UploadedFile {#45
-test: false
-originalName: "error.JPG"
-mimeType: "image/jpeg"
-size: 21806
-error: 0
path: "C:\xampp\tmp"
filename: "php639F.tmp"
basename: "php639F.tmp"
pathname: "C:\xampp\tmp\php639F.tmp"
extension: "tmp"
realPath: "C:\xampp\tmp\php639F.tmp"
aTime: 2018-05-17 04:26:29
mTime: 2018-05-17 04:26:29
cTime: 2018-05-17 04:26:29
inode: 0
size: 21806
perms: 0100666
owner: 0
group: 0
type: "file"
writable: true
readable: true
executable: false
file: true
dir: false
link: false
linkTarget: "C:\xampp\tmp\php639F.tmp"
}
]
]
]
}
My main objective is to store the uploaded file on the server disk and save its filename in the database.