I have 2 questions...
1. When I send file Request in saveAttachment() method is empty ([]).
2. Is my procedure okay for saving file as binary in database?
Laravel Migration:
class CreateAttachmentsTable extends Migration
{
public function up()
{
Schema::create('attachments', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->binary('content');
});
}
}
Laravel Controller:
public function saveAttachment(Request $request)
{
if ($request->file) {
$attachment = new Attachment();
$attachment->content = $request->file;
$attachment->save();
}
}
Angular Component:
onFileChange(event) {
if (event.target.files.length > 0) {
this.service.saveAttachment(event.target.files[0]).subscribe();
}
}
Angular Service:
saveAttachment(file: File) {
return this.http.post(USER_API_URL + '/saveAttachment, { file: file });
}
Thanks.
I found a solution but it's not the best probably...
Laravel Migration:
Laravel Controller:
Angular Component:
Angular Service: