Jun 1, 2024
0
Level 1
Help with spatie media library
Hey,
I am trying to upload a file to my S3 bucket. But whenever I use the toMediaCollection function, the request loads for a very long time and aborts at some point without error. I have tried all debug possibilities and just get no error. But the S3 is configured correctly and the user has full access.
public function store(StoreTemporaryUploadRequest $request)
{
$user = $request->user();
$temporaryUpload = TemporaryUpload::create([
'user_id' => $user->id
]);
$temporaryUpload->addMedia($request->file('file')); // When using ->toMediaCollection() or ->toMediaCollection('media')
return response()->json(['message' => 'File uploaded successfully', 'data' => $temporaryUpload], 201);
}
Model:
class TemporaryUpload extends Model implements HasMedia
{
use InteractsWithMedia;
protected $fillable = [
'user_id'
];
// Tried to use this
public function registerMediaCollections(): void
{
$this->addMediaCollection('media')->useDisk('s3');
}
}
Edit:
I saw that there is a entry in the media table
10 App\Models\TemporaryUpload 24 393de788-8bbc-4347-ac0d-31f00a7dd9d1 media image image.jpg image/png s3 s3 224144 [] [] [] [] 1 2024-06-01 17:36:11 2024-06-01 17:36:11
But there is no file in the bucket
Please or to participate in this conversation.