Javascript 在显影模式下,是否可以渲染存储在laravel存储器中的图像?
我正在使用Javascript 在显影模式下,是否可以渲染存储在laravel存储器中的图像?,javascript,php,reactjs,laravel,Javascript,Php,Reactjs,Laravel,我正在使用React和Laravel开发一个web应用程序,这是两个独立的项目,我正在尝试使用我获得的URL,例如/storage/file name.png将从Laravel存储中获取的图像渲染到img标记中 这是我的表演方法: public function show(Patient $patient) { $this->response = new stdClass(); ...My code $this->resp
React
和Laravel
开发一个web应用程序,这是两个独立的项目,我正在尝试使用我获得的URL,例如/storage/file name.png
将从Laravel
存储中获取的图像渲染到img
标记中
这是我的表演方法:
public function show(Patient $patient)
{
$this->response = new stdClass();
...My code
$this->response->image = Storage::url($patient->user->image);
...My code
return response()->json($this->response, $this->successStatus)->header('content-type', 'application/json');
}
在我的react应用程序中,我将URL传递给包含img
标记的组件作为道具,但没有显示任何内容。我尝试添加http://localhost:8000
添加到/storage/file name.png
,结果相同
附言:我的控制台记录了图像
道具,它返回的/storage/file name.png
是正确的
以下是我的dropzone组件渲染方法:
render() {
const { isHighLight } = this.state;
const { isMultiple, isEnabled, title, image } = this.props;
return (
<div
className={classNames({
dropzone: true,
'dropzone--disbaled': !isEnabled,
'dropzone--highlight': isHighLight
})}
role='presentation'
onClick={this.handleDropzoneClick}
onDragLeave={this.handleDragLeave}
onDragOver={this.handleDragOver}
onDrop={this.handleDrop}
>
<img src={image} alt='dropzone' className='dropzone__img' />
<input ref={this.fileInputRef} type='file' className='dropzone__input' multiple={isMultiple} onChange={this.handleFileUploaded} />
<span className='dropzone__title'>{title}</span>
</div>
);
}
render(){
const{isHighLight}=this.state;
const{isMultiple,isEnabled,title,image}=this.props;
返回(
{title}
);
}
在显影模式下,是否有图像显示功能?或者我应该在某个地方托管我的应用程序,以便能够显示图像吗?默认情况下,前端应用程序无权查看存储路径中的文件 您可以尝试在base64中转换文件:
public function getFile(string $name)
{
if (file_exists("storage/{$name}")) {
return base64_encode(file_get_contents("storage/{$name}"));
}
}
前端:
<img src="data:image/png;base64, base64 code here">
您需要提供一个更好的示例,这里缺少与React应用程序相关的代码。请通读,请提供一些前端代码。还有,您是否创建了符号链接?听起来这更像是虚拟主机设置的问题。您需要为这两个代码库设置一个虚拟主机。我更新了问题@rhys_stubbs@Juakali92是的,我想过,但我不知道从哪里开始