1

I want to inject full path to my media in admin of API-platform with following this doc

was impossible to generate full path URI I try this:

 field.field = props => (
                        <ImageField source="contentUrl"  {...props} >
                            <FunctionField render={ render => {
                                console.log(render)
                                return `${process.env.REACT_APP_API_ENTRYPOINT}/media/${render.contentUrl}`
                            }}  />
                        </ImageField>
                    );

from: this stack

I obtain this result:

<img src="[object Object]" class="ImageField-image-274">

my src needs to be:

http://localhost:8080/media/myFile.jpg

from my api:

contentUrl = myFile.jpg

I need concat this with process.env.REACT_APP_API_ENTRYPOINT

thanks for your help!

Sayed Mohd Ali
  • 2,156
  • 3
  • 12
  • 28
darkiron
  • 1,174
  • 1
  • 10
  • 20

2 Answers2

0

Did you set the variable before you start the webpack dev server or before you build your project?

export REACT_APP_API_ENTRYPOINT=http://localhost/....
npm start 
Buddy
  • 10,874
  • 5
  • 41
  • 58
Thomas Halwax
  • 193
  • 1
  • 10
0

You can use FunctionField like this:

<FunctionField
      label="Image"
      render={(record: any) => {
        return (
          <img
            src={`${process.env.REACT_APP_API_ENTRYPOINT}/media/${record.contentUrl}`}
          />
        );
      }}
    />