I have seen other answers on Stack Overflow for this, but still I am unable to resolve the issue.
If I download a JSON file, I am able to successfully read the contents. See below code:
BELOW CODE WORKS FINE WHEN I DOWNLOAD JSON TEXT FILE FROM AWS S3:-
var result = await Storage.get('simplejsonfile', {
level: 'private',
cacheControl: 'no-cache',
download: true
});
var user_data = await new Response(result.Body).json();
console.log(user_data); // this displays the JSON correctly. Works Fine !
The above code snippet just establishes that all my configurations are correct, because I am correctly able to download JSON file from AWS S3 using amplify and then read it.
THE PROBLEM (WHEN I DOWNLOAD IMAGE I AM UNABLE TO DISPLAY IT LATER):-
I have an image abc.png on AWS S3 bucket. I have manually uploaded this image. I try to download and display on my mobile device. Its not working.
Also see the comments in code below:
const [mystate, setTheImage] = useState();
...
const getResponse = await Storage.get('abc.png', {
level: 'private',
// cacheControl: 'no-cache',
contentType: 'image/png',
// contentType: string,
download: true
});
var mydata = await new Response(getResponse.Body).text();
console.log(String(mydata)); //displays star & diamond symbols and PNG prefix on console
setTheImage(mydata); // set state mystate
later ...
<Image source={{uri:mystate}} style={{ width: '100%', height: '60%' , resizeMode: 'contain' />
But I am unable to display the image. Preferably I only want to work with amplify library and dont want to install any more extra library just for this.