How to retrieve FormData in Laravel
How to retrieve FormData in Laravel
I am sending formdata from Angular 2 to Laravel API to save the recorded voice from RecordRTC js. Checked the filename, filetype and blob file on console. it is showing. but not able to retrieve on Laravel backend code.
public uploadToServer() 'audio';
let fileName = (Math.random() * 1000).toString().replace('.', '');
if (fileType === 'audio')
fileName += '.' + (!!navigator.mozGetUserMedia ? 'ogg' : 'wav');
else
fileName += '.webm';
// create FormData
var formData: FormData = new FormData();
console.log(fileName);
console.log(blob);
console.log(fileType);
formData.append(fileType + '-filename', fileName);
formData.append(fileType + '-blob', blob);
console.log(formData);
this.recordingService.saveRecording(formData).subscribe(
data => this.saveRecordingSuccess(data),
error => this.saveRecordingFail(error)
);
Laravel Code:-
public function saveRecording(Request $request)
In laravel code I have not receiving any files and post data.
FormData
Edited my question please check it once.
– Maneesh Rao
Jun 18 at 14:19
You don't use
$_FILES
in Laravel. You should be using $request->file('audio-blob')
. As @thefallen suggests, you should read up on File uploads using Laravel. What do you get if you do dd($request->files())
in your saveRecording
function?– Niraj Shah
Jun 18 at 20:54
$_FILES
$request->file('audio-blob')
dd($request->files())
saveRecording
It is showing empty.
– Maneesh Rao
Jun 19 at 5:10
Fixed the issue. var reader = new FileReader(); var data = ; reader.readAsDataURL(this.recordRTC.getBlob()); reader.onload = function () data = value: reader.result.split(',')[1], filename: fileName, fileType: fileType ; console.log(reader.result.split(',')[1]); ;
– Maneesh Rao
Jun 19 at 17:40
1 Answer
1
You have to put on your form the mime type, like in JQuery Ajax, have the property
mimeType: "multipart/form-data"
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
You might want to check some doc, this is not a correct way to send a file with
FormData
.– thefallen
Jun 18 at 14:15