【问题标题】:Laravel 5 - Blob doesn't retrive an image rightLaravel 5 - Blob 无法正确检索图像
【发布时间】:2018-06-11 12:46:18
【问题描述】:

我正在使用 Laravel 存储图像(从画布生成),但是当我从列中检索值并将其传递给块的“src”属性时,它不会加载并进入浏览器控制台我看到了错误

“加载资源失败:net::ERR_INVALID_URL”

迁移

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTblTaccuinoTable extends Migration
{
/**
 * Schema table name to migrate
 * @var string
 */
public $set_schema_table = 'tbl_taccuino';

/**
 * Run the migrations.
 * @table tbl_taccuino
 *
 * @return void
 */
public function up()
{
    if (Schema::hasTable($this->set_schema_table)) return;
    Schema::create($this->set_schema_table, function (Blueprint $table) {
        $table->engine = 'InnoDB';
        $table->increments('id_taccuino');
        $table->integer('id_paziente')->unsigned();
        $table->string('taccuino_descrizione', 45);
        $table->date('taccuino_data');
        $table->binary('taccuino_report_anteriore');
        $table->binary('taccuino_report_posteriore');

        $table->index(["id_paziente"], 'fk_tbl_taccuino_tbl_pazienti1_idx');


        $table->foreign('id_paziente', 'fk_tbl_taccuino_tbl_pazienti1_idx')
            ->references('id_paziente')->on('tbl_pazienti')
            ->onDelete('no action')
            ->onUpdate('no action');
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
 public function down()
 {
   Schema::dropIfExists($this->set_schema_table);
 }
}

型号

<?php

/**
* Created by Reliese Model.
* Date: Mon, 25 Dec 2017 12:47:05 +0000.
*/

namespace App\Models\Patient;

use Reliese\Database\Eloquent\Model as Eloquent;

/**
 * Class Taccuino
 * 
 * @property int $id_taccuino
 * @property int $id_paziente
 * @property string $taccuino_descrizione
 * @property \Carbon\Carbon $taccuino_data
 * @property boolean $taccuino_report_anteriore
 * @property boolean $taccuino_report_posteriore
 * 
 * @property \App\Models\Pazienti $tbl_pazienti
 *
 * @package App\Models
 */
class Taccuino extends Eloquent
{
protected $table = 'tbl_taccuino';
protected $primaryKey = 'id_taccuino';
public $incrementing = false;
public $timestamps = false;

protected $casts = [
    'id_taccuino' => 'int',
    'id_paziente' => 'int',
];

protected $dates = [
    'taccuino_data'
];

protected $fillable = [
    'id_paziente',
    'taccuino_descrizione',
    'taccuino_data',
    'taccuino_report_anteriore',
    'taccuino_report_posteriore'
];

public function tbl_pazienti()
{
    return $this->belongsTo(\App\Models\Patient\Pazienti::class, 'id_paziente');
}
}

在我的刀片视图中

<img id="canvas_dolore" class="M" src="{{$record->taccuino_report_anteriore }}"></img>

PS:blob字符串值以

开头
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA..."

【问题讨论】:

    标签: database image laravel laravel-5 blob


    【解决方案1】:

    您可以尝试为图像输出未转义的 src 值:

    <img src="{!! ... !!}">
    

    【讨论】:

    • 您能否给我们指出一个不起作用的示例,以便我们查看该页面?您可以通过 JSFiddle 或类似应用程序的 HTML 输出吗?这将有很大帮助。 :)
    猜你喜欢
    • 2020-12-14
    • 2015-06-02
    • 1970-01-01
    • 2012-04-28
    • 2019-11-24
    • 1970-01-01
    • 2019-01-25
    • 2015-02-17
    • 2019-12-28
    相关资源
    最近更新 更多