Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom properties - TypeError: Failed to execute 'append' on 'FormData': parameter 2 is not of type 'Blob'. #357

Closed
dvorakvaclav opened this issue Oct 25, 2022 · 5 comments · Fixed by #409

Comments

@dvorakvaclav
Copy link

Hello,

I am facing the same issue mentioned in #288 when saving resource with new image with filled custom properties. When custom properties are not filled, everything works fine. Can anyone help? Thanks

Model:

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;

class Partner extends Model implements HasMedia
{
    use InteractsWithMedia;

    const MEDIA_LOGO = 'logo';

    protected $guarded = [];
    
    public function registerMediaCollections(): void
    {
        $this->addMediaCollection(self::MEDIA_LOGO);
    }
}

Resource:

Images::make('Logos', \App\Models\Partner::MEDIA_LOGO)
    ->rules('nullable')
    ->customPropertiesFields([
        Text::make('URL', 'url'),
    ]),

Error:

"TypeError: Failed to execute 'append' on 'FormData': parameter 2 is not of type 'Blob'.
    at http://127.0.0.1:8000/nova-api/scripts/media-lib-images-field:2:187335
    at Proxy.forEach (<anonymous>)
    at Proxy.fill (http://127.0.0.1:8000/nova-api/scripts/media-lib-images-field:2:186802)
    at http://127.0.0.1:8000/vendor/nova/app.js?id=352142bf8c8417d0a082d18681d3234b:1:919324
    at e.exports (http://127.0.0.1:8000/vendor/nova/vendor.js?id=469a2eb2ac0a02b4147b36a36a3c39c1:2:909411)
    at e.exports (http://127.0.0.1:8000/vendor/nova/vendor.js?id=469a2eb2ac0a02b4147b36a36a3c39c1:2:941060)
    at http://127.0.0.1:8000/vendor/nova/app.js?id=352142bf8c8417d0a082d18681d3234b:1:919307
    at e.exports (http://127.0.0.1:8000/vendor/nova/vendor.js?id=469a2eb2ac0a02b4147b36a36a3c39c1:2:909411)
    at e.exports (http://127.0.0.1:8000/vendor/nova/vendor.js?id=469a2eb2ac0a02b4147b36a36a3c39c1:2:941060)
    at http://127.0.0.1:8000/vendor/nova/app.js?id=352142bf8c8417d0a082d18681d3234b:1:919286"
@thettler
Copy link

thettler commented Nov 2, 2022

The Issue appears if you try to add a new Image and edit the Custom Properties directly.

image: JSON.parse(JSON.stringify(this.modelValue)),

This line takes the image object and clones it into the Custom Properties component. By using the JSON parse/stringify the Blob in the file property gets casted to a normal object. this then triggers the error.

An easy fix would be to use the Lodash Clone functionality, or even better to just emit the custom properties and add them in the Gallery.vue to the corresponding images.

I am sure i can quickly cook up a PR with the lodash clone fix. I do not know if the other solution has any drawbacks i do not know about. Feel free to contact me if you would like to see a PR with this Solution though @ebess

thettler added a commit to thettler/advanced-nova-media-library that referenced this issue Nov 2, 2022
@CosmicodeStudio
Copy link

@ebess Can you accept this?

@SchwartzN
Copy link

Hello @ebess can you accept this pull request ?

@aurelien-ci
Copy link

Hello @ebess can you accept this ? It solves the problem for me

tobias-grasse added a commit to tobias-grasse/advanced-nova-media-library that referenced this issue Aug 22, 2023
… custom properties

When custom properties were set for a newly added file, stringifying the image object would replace the file Blob with a plain object containing just the file name. This change ensures that newly added files are retained after their custom properties are modified before submission.

Signed-off-by: Tobias Grasse <tg@glancr.de>
tobias-grasse added a commit to tobias-grasse/advanced-nova-media-library that referenced this issue Aug 22, 2023
… custom properties

When custom properties were set for a newly added file, stringifying the image object would replace the file Blob with a plain object containing just the file name. This change ensures that newly added files are retained after their custom properties are modified before submission.

Signed-off-by: Tobias Grasse <tg@glancr.de>
bkintanar pushed a commit that referenced this issue Aug 22, 2023
…om properties (#409)

When custom properties were set for a newly added file, stringifying the image object would replace the file Blob with a plain object containing just the file name. This change ensures that newly added files are retained after their custom properties are modified before submission.

Signed-off-by: Tobias Grasse <tg@glancr.de>
@aurelien-ci
Copy link

Thank you !

Gompje pushed a commit to DaktaDeo/advanced-nova-media-library that referenced this issue Mar 29, 2024
… custom properties (ebess#409)

When custom properties were set for a newly added file, stringifying the image object would replace the file Blob with a plain object containing just the file name. This change ensures that newly added files are retained after their custom properties are modified before submission.

Signed-off-by: Tobias Grasse <tg@glancr.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants