Upload an image from UI-extension

Hi,

I’m trying to upload an image inside a UI-extension.

The contentful-management.js have a createAssetFromFiles function, but UI-extension SDK haven’t. How do I upload a picture?

Thanks,
Vincenzo

Hey @vmilone!

If I got your use case correctly you can try with this one https://github.com/contentful/ui-extensions-sdk/blob/master/docs/ui-extensions-sdk-frontend.md#extensionfieldsetvaluevalue-promisevoid.
So, value would match the field type (for example, Media).

Let me know if I misunderstood your scenario, I’ll try to help :wink:

Hi @andrey,

it’s not helping. I must upload a new file and then create a new Asset with the uploaded file.

Vincenzo

Hi @vmilone!

As you noticed, the UI Extensions SDK doesn’t support that feature yet. It’s still relatively recent and the sdk hasn’t caught up yet.

My advise is to import the CMA SDK into your UI Extension (just as you would any 3rd party library), and use that to upload images.

NOTE:
Unfortunately, this requires hard coding a CMA token into the UI Extension. Please create a user specifically for that purpose. You can call it something self explanatory like “UI Extension Bot”. If you have custom roles & permissions available in your accounts, I further recommend you deny all access to that bot user except for the media library.

2 Likes

We are having the same issue but we cannot add the CMA to the client, even if that CMA only has access to the media library. Is there any update on this issue? Has the UI Extensions SDK caught up and implemented this method?