Are you sure that Storage::disk(... is returning the filename?
Are there any errors in the laravel log?
Do you get success message?
Hi everyone, hope all is well. I am having this problem. I have created a form where you can upload video files, but I notice that when uploading it, video takes time to upload depending on the size of the file,so to avoid people staring at a screen for a long time waiting for their video to upload I saw this example on the this website about creating a progress bar. I tried it out and yes its working, like it saves to the public app folder and also it saves to my aws3 bucket folder as I requested but I noticed that its not saving the file in the database and I don't know why it by passes the database. here is my code below
//fileUpload.blade.php
<div class="container">
<div class="card">
<div class="card-header">
</div>
<div class="card-body">
<form method="POST" action="{{ route('fileUploadPost') }}" enctype="multipart/form-data">
@csrf
<div class="form-group">
<input name="file" id="poster" type="file" class="form-control"><br/>
<div class="progress">
<div class="bar"></div >
<div class="percent">0%</div >
</div>
<input type="submit" value="Submit" class="btn btn-success">
</div>
</form>
</div>
</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<script type="text/javascript">
function validate(formData, jqForm, options) {
var form = jqForm[0];
if (!form.file.value) {
alert('File not found');
return false;
}
}
(function() {
var bar = $('.bar');
var percent = $('.percent');
var status = $('#status');
$('form').ajaxForm({
beforeSubmit: validate,
beforeSend: function() {
status.empty();
var percentVal = '0%';
var posterValue = $('input[name=file]').fieldValue();
bar.width(percentVal)
percent.html(percentVal);
},
uploadProgress: function(event, position, total, percentComplete) {
var percentVal = percentComplete + '%';
bar.width(percentVal)
percent.html(percentVal);
},
success: function() {
var percentVal = 'Wait, Saving';
bar.width(percentVal)
percent.html(percentVal);
},
complete: function(xhr) {
status.html(xhr.responseText);
alert('Uploaded Successfully');
window.location.href = "file-upload";
}
});
})();
</script>
//file-upload controller
public function fileUploadPost(Request $request)
{
$request->validate([
'file' => 'required',
]);
$my_video=new Video;
$fileName = time().'.'.request()->file->getClientOriginalName();
request()->file->move(public_path('/app'), $fileName);
$name_file=uniqid().'video.mp4';
$fmpeg=FFMpeg::fromDisk('local')
->open($fileName)
->addFilter(function ($filters) {
$filters->resize(new \FFMpeg\Coordinate\Dimension(640, 480));
})
->export()
->toDisk('s3')
->inFormat(new \FFMpeg\Format\Video\X264('libmp3lame'))
->save($name_file);
$imageName = Storage::disk('s3')->url($name_file);
$my_video->title=$imageName;
$my_video->save();
return response()->json(['success'=>'You have successfully upload file.']);
}
}
Are you sure that Storage::disk(... is returning the filename?
Are there any errors in the laravel log?
Do you get success message?
Please or to participate in this conversation.