jeudi 23 juin 2016

React Native Image throw NSURLErrorDomain error 403

I'm trying to show an image inside S3 accessed via cloudfront:

import React from 'react'
import { View, Image } from 'react-native'

module.exports = React.createClass({
    render() {
        let url = 'https://d2u2j4yr3sejbq.cloudfront.net/media/eff587d9-11fc-43d0-853d-8f65815de50a.png'

        Image.prefetch(url)
        .then((resolve, reject) => {
            console.log('succeed')
            resolve()
        }).catch((err) => {
            console.log(err)
        })

        return (
            <View>
                <Image source={{ uri: url }} style={{ width: 100, height: 100 }} />
            </View>
        )
    }
})

Log from chrome console:

Error: The operation couldn’t be completed. (NSURLErrorDomain error 403.)
    at createErrorFromErrorData (http://localhost:8081/index.ios.bundle?platform=ios&dev=true:7090:11)
    at http://localhost:8081/index.ios.bundle?platform=ios&dev=true:7041:11
    at MessageQueue.__invokeCallback (http://localhost:8081/index.ios.bundle?platform=ios&dev=true:6907:10)
    at http://localhost:8081/index.ios.bundle?platform=ios&dev=true:6793:8
    at guard (http://localhost:8081/index.ios.bundle?platform=ios&dev=true:6735:1)
    at MessageQueue.invokeCallbackAndReturnFlushedQueue (http://localhost:8081/index.ios.bundle?platform=ios&dev=true:6792:1)
    at DedicatedWorkerGlobalScope.onmessage (http://localhost:8081/debuggerWorker.js:39:56)

I've tried to access directly using the S3 url but same bug, I can access to the image without problem here.

PS: there's an issue with the same error in another library rs/SDWebImage I don't know if could be related, the say that is "because is need User-Agent"

Using:

"react": "^15.1.0",

"react-native": "0.27.2",

Thanks...

Aucun commentaire:

Enregistrer un commentaire