Change format for upload

This commit is contained in:
philipp lang 2024-07-13 19:49:31 +02:00
parent a6c11cdc14
commit 59d7647720
2 changed files with 22 additions and 0 deletions

View File

@ -50,6 +50,9 @@ class MediaController
$file = new MediaFile($c['name']);
$file->setBasename($collection->runCallback('forceFileName', $model, $file->getBasename()));
if ($collection->runCallback('convert') !== null) {
$file->setExtension($collection->runCallback('convert'));
}
$adder = $this->fileAdderFromData($model, $c['content'], $collection)
->usingName($file->getBasename())
->usingFileName($file->getFilename())

View File

@ -34,6 +34,25 @@ test('it uploads a single file to a single file collection', function () {
$response->assertJsonMissingPath('model_id');
});
test('it changes format', function () {
$this->auth()->registerModel();
$post = $this->newPost();
$content = base64_encode($this->pngFile()->getContent());
$response = $this->postJson('/mediaupload', [
'parent' => ['model' => 'post', 'collection_name' => 'singleJpegFile', 'id' => $post->id],
'payload' => [
'content' => $content,
'name' => 'beispiel bild.png',
],
]);
$response->assertStatus(201)
->assertJsonPath('size', 366471)
->assertJsonPath('file_name', 'beispiel-bild.jpg')
->assertJsonPath('mime_type', 'image/jpeg');
});
test('it uploads a single image to a single file collection', function () {
$this->auth()->registerModel()->withoutExceptionHandling();
$post = $this->newPost();