question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Currently I want to load image from url not from local, and this is the code I use and it is not working, please help me to resolve this

        <Svg
          width= {Layout.window.width}
          height={Layout.window.height/2}
        >
          <Circle
            cx={data.xAxis}
            cy={data.yAxis}
            r="10"
            fill={data.departmentColorCode}
          />
          <Image
                    width="100%"
                    height="100%"
                    preserveAspectRatio="xMidYMid slice"
                    opacity={0.5}
                 href={{uri:data.floorImage}}/>
        </Svg>
      </View>

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:17

github_iconTop GitHub Comments

8reactions
nadudecommented, Jun 18, 2017

This seems to work for me href={{ uri: '<remote-image-url', __packager_asset:true }} . Good luck! @hle50 @ @fendorio @magicismight

3reactions
ricklanceecommented, Feb 27, 2018

hi @msand does this only work for apps via expo and not when importing Image from react-native-svg? Just tried this in a plain react native project i get the error:

JSON value '{
    uri = "https://avatars2.githubusercontent.com/u/1131362?s=460&v=4";
}' of type NSMutableDictionary cannot be converted to an image. Only local files or data URIs are supported.

Do we have to convert the image to a data uri before passing it into the href?

Edit: Using react-native-fetch-blob and using it as a temp file uri works.

import React from 'react'
import RNFetchBlob from 'react-native-fetch-blob'

import Svg, {
    Image,
} from 'react-native-svg'

import { View } from 'react-native'

class SvgImage extends React.Component {

    state = {
        uri: undefined,
    }

    async componentWillMount() {
        const res = await RNFetchBlob
           .config({
              // add this option that makes response data to be stored as a file,
              // this is much more performant.
              fileCache : true,
              // by adding this option, the temp files will have a file extension
             appendExt : 'jpg',
           })
          .fetch('GET', 'https://avatars2.githubusercontent.com/u/1131362?s=460&v=4')
       
        this.setState({
            uri: `file://${res.path()}`,
        })
    }

   render() {
        const { uri } = this.state

        return (
            <View>
                <Svg
                    height="100"
                    width="100"
                    viewBox="0 0 100 100"
                >
                    <Image
                        x="0"
                        y="0"
                        width="100%"
                        height="100%"
                        preserveAspectRatio="xMidYMid slice"
                        href={!uri ? require('./placeholder.png') : { uri }}
                    />
                </Svg>
            </View>
        )
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Find the URL of a page or image - Computer - Google Support
Get an image URL · On your computer, go to images.google.com. · Search for the image. · In Images results, click the image....
Read more >
ImgBB — Upload Image — Free Image Hosting
Free image hosting and sharing service, upload pictures, photo host. Offers integration solutions for uploading images to forums.
Read more >
4 Ways to Get the URL for Pictures - wikiHow
1. Open the Google Image search page. Go to https://images.google.com/ in your computer's web browser. This will open the Google search page for...
Read more >
HTML Images - W3Schools
The HTML <img> tag is used to embed an image in a web page. Images are not technically ... The required src attribute...
Read more >
20+ Free Url & Link Images - Pixabay
Related Images: link domain web internet website youtube domain names hyperlink sea. Hundreds of url images to choose from. Free high resolution picture ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found