Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/MediaUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ class MediaUpload extends Model
'disk',
];

/**
* New Nova uploads go to the main S3 disk. The resources bucket
* currently denies PutObject for the shared IAM user.
*/
protected $attributes = [
'disk' => 's3',
];

public function getResolvedUrlAttribute(): ?string
{
if (empty($this->file_path)) {
return null;
}

return Storage::disk($this->disk ?: 'resources')->url($this->file_path);
return Storage::disk($this->disk ?: 's3')->url($this->file_path);
}
}
4 changes: 2 additions & 2 deletions app/Nova/Actions/BulkUploadMediaFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function handle(ActionFields $fields, Collection $models)
$safeBaseName = Str::slug($baseName) ?: 'upload-file';
$destination = 'nova/uploads/' . now()->format('Y/m');
$finalFileName = $safeBaseName . '-' . Str::random(8) . '.' . $extension;
$storedPath = $file->storeAs($destination, $finalFileName, 'resources');
$storedPath = $file->storeAs($destination, $finalFileName, 's3');

if (!$storedPath) {
$skipped++;
Expand All @@ -74,7 +74,7 @@ public function handle(ActionFields $fields, Collection $models)
MediaUpload::create([
'title' => trim(str_replace(['-', '_'], ' ', $baseName)),
'file_path' => $storedPath,
'disk' => 'resources',
'disk' => 's3',
]);

$uploaded++;
Expand Down
4 changes: 2 additions & 2 deletions app/Nova/MediaUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ public function fields(Request $request): array
})->onlyOnIndex(),

File::make('File', 'file_path')
->disk('resources')
->disk('s3')
->path('nova/uploads')
->prunable()
->creationRules('required')
->rules('required', 'max:51200', 'mimes:jpg,jpeg,png,gif,webp,svg,pdf,doc,docx,ppt,pptx,xls,xlsx,txt')
->help('Uploads directly to S3 disk "resources" under folder "nova/uploads".'),
->help('Uploads to the main S3 disk under folder "nova/uploads".'),

Text::make('URL', function () {
return $this->renderUrlWithCopy($this->resolved_url);
Expand Down
Loading