使用Laravel Nova上载大型文件
我有一个使用Vapor部署的Laravel应用程序(v6.x) 我正在尝试使用Laravel Nova中的表单上传一个文件 Nova提供了多种上传方式,一种是使用自己的实现以便于使用,另一种是开发人员有更多的控制权 标准代码:使用Laravel Nova上载大型文件,laravel,file-upload,laravel-vapor,Laravel,File Upload,Laravel Vapor,我有一个使用Vapor部署的Laravel应用程序(v6.x) 我正在尝试使用Laravel Nova中的表单上传一个文件 Nova提供了多种上传方式,一种是使用自己的实现以便于使用,另一种是开发人员有更多的控制权 标准代码: public function fields(Request $request) { return [ File::make('file') ->disk('s3')
public function fields(Request $request)
{
return [
File::make('file')
->disk('s3')
->storeSize('attachment_size')->nullable()
->path('ID-'.$request->associatedId)
->putFile()
->hideWhenUpdating()
->hideFromIndex(),
];
}
和"控制":
只要文件大小约为~3MB或更少,这两种方法都可以工作。但是,我需要上传大约20~200MB大小的文件
每当我尝试提交表单时,所有信息都会存储到数据库中,并且不会显示任何错误。遗憾的是,文件字段没有填充,也没有进行上传
我需要做什么才能在Laravel nova中实现大文件上传 尝试VaporImage/VaporImage(Laravel\Nova\Fields\VaporImage)而不是文件/图像 这是我的代码:
return [
ID::make()->sortable(),
Text::make('Name')->sortable(),
Text::make('Original Filename')->readonly()->exceptOnForms(),
Text::make('Content Type')->readonly()->exceptOnForms(),
Text::make('Size')->readonly()->exceptOnForms(),
Text::make('path')->readonly()->onlyOnDetail(),
DateTime::make('Approved At')->sortable()->exceptOnForms(),
VaporImage::make('Path')
->path('/assets')
->storeOriginalName('original_filename')
->storeOriginalSize('size')
->storeOriginalMimeType('content_type'),
];
VaporImage类中不存在诸如storeOriginalSize和StoreOriginalMiType之类的函数,这就是为什么我创建了自己的VaporImage类并扩展了Laravel的VaporImage
这是我自己的蒸发年龄课程:
<?php
namespace App\Nova\Core;
use Illuminate\Support\Facades\Storage;
use Laravel\Nova\Fields\VaporImage as NovaVaporImage;
class VaporImage extends NovaVaporImage
{
/**
* The column where the file's original size should be stored.
*
* @var string
*/
public $size;
/**
* The column where the file's original mimeType should be stored.
*
* @var string
*/
public $mimeType;
/**
* Specify the column where the file's original size should be stored.
*
* @param string $column
* @return $this
*/
public function storeOriginalSize($column)
{
$this->size = $column;
return $this;
}
/**
* Specify the column where the file's original mimeType should be stored.
*
* @param string $column
* @return $this
*/
public function storeOriginalMimeType($column)
{
$this->mimeType = $column;
return $this;
}
/**
* Merge the specified extra file information columns into the storable attributes.
*
* @param \Illuminate\Http\Request $request
* @param array $attributes
* @return array
*/
protected function mergeExtraStorageColumns($request, array $attributes)
{
if ($this->originalNameColumn) {
$attributes[$this->originalNameColumn] = $request->input($this->attribute);
}
if ($this->size) {
$attributes[$this->size] = Storage::size($request->input('vaporFile')['key']);
}
if ($this->mimeType) {
$attributes[$this->mimeType] = Storage::mimeType($request->input('vaporFile')['key']);
}
return $attributes;
}
尝试VaporImage/VaporImage(Laravel\Nova\Fields\VaporImage)而不是文件/图像
这是我的代码:
return [
ID::make()->sortable(),
Text::make('Name')->sortable(),
Text::make('Original Filename')->readonly()->exceptOnForms(),
Text::make('Content Type')->readonly()->exceptOnForms(),
Text::make('Size')->readonly()->exceptOnForms(),
Text::make('path')->readonly()->onlyOnDetail(),
DateTime::make('Approved At')->sortable()->exceptOnForms(),
VaporImage::make('Path')
->path('/assets')
->storeOriginalName('original_filename')
->storeOriginalSize('size')
->storeOriginalMimeType('content_type'),
];
VaporImage类中不存在诸如storeOriginalSize和StoreOriginalMiType之类的函数,这就是为什么我创建了自己的VaporImage类并扩展了Laravel的VaporImage
这是我自己的蒸发年龄课程:
<?php
namespace App\Nova\Core;
use Illuminate\Support\Facades\Storage;
use Laravel\Nova\Fields\VaporImage as NovaVaporImage;
class VaporImage extends NovaVaporImage
{
/**
* The column where the file's original size should be stored.
*
* @var string
*/
public $size;
/**
* The column where the file's original mimeType should be stored.
*
* @var string
*/
public $mimeType;
/**
* Specify the column where the file's original size should be stored.
*
* @param string $column
* @return $this
*/
public function storeOriginalSize($column)
{
$this->size = $column;
return $this;
}
/**
* Specify the column where the file's original mimeType should be stored.
*
* @param string $column
* @return $this
*/
public function storeOriginalMimeType($column)
{
$this->mimeType = $column;
return $this;
}
/**
* Merge the specified extra file information columns into the storable attributes.
*
* @param \Illuminate\Http\Request $request
* @param array $attributes
* @return array
*/
protected function mergeExtraStorageColumns($request, array $attributes)
{
if ($this->originalNameColumn) {
$attributes[$this->originalNameColumn] = $request->input($this->attribute);
}
if ($this->size) {
$attributes[$this->size] = Storage::size($request->input('vaporFile')['key']);
}
if ($this->mimeType) {
$attributes[$this->mimeType] = Storage::mimeType($request->input('vaporFile')['key']);
}
return $attributes;
}
这可能是Web服务器配置/php配置问题。到目前为止,我只能找到设置PHP版本的选项,而不能直接调整任何PHP设置。还有其他上传大文件的方法吗?@onlinehomas我已经对我的本地项目进行了测试,限制有所增加。它似乎起作用了!所以我现在需要弄清楚的就是如何使用Vapor更改Laravel应用程序的PHP设置;ini_集('upload_max_filesize','64M');在代码中,您可以将其放在appserviceprovider@onlineThomas谢谢你,我试过了,但遗憾的是它不起作用。我确实遇到了别的事情。就是这个。我希望把它和这个结合起来。这样我就不会被迫更改php设置。然而,这也带来了我试图解决的问题。我不会把这些贴在这里,以防止淡化这个问题。我将描述的解决方案可能是Web服务器配置/php配置问题。到目前为止,我只能找到设置PHP版本的选项,而不能直接调整任何PHP设置。还有其他上传大文件的方法吗?@onlinehomas我已经对我的本地项目进行了测试,限制有所增加。它似乎起作用了!所以我现在需要弄清楚的就是如何使用Vapor更改Laravel应用程序的PHP设置;ini_集('upload_max_filesize','64M');在代码中,您可以将其放在appserviceprovider@onlineThomas谢谢你,我试过了,但遗憾的是它不起作用。我确实遇到了别的事情。就是这个。我希望把它和这个结合起来。这样我就不会被迫更改php设置。然而,这也带来了我试图解决的问题。我不会把这些贴在这里,以防止淡化这个问题。我将描述的解决方案。