2

Problem Statement:

I´am uploading an image uri base64 from my react-native app to my java backend server. My backend converts the URI String to a byte array and stores it in the MySQL Database (with a BLOB). So far it´s all fine! But when I'am reading/fetching the images from the database I convert them back to a base64 image uri string, to show them to the user (fetching with my Rest api). The problem is, that my Rest API (GET) can handle like 2-3 images and then it runs out of memory... What can I do? It´s because the base64 uri strings are obviously too long for the Rest API...

Any resolution?

WindyCode
  • 23
  • 6

1 Answers1

0

In your backend, you should store images as files, not byte array. Convert b64 to file in java with something like this (I don't personally know how to do it)

Once you've done this, your backend has to return you the file's url so you can display it in your app with the Image component from react-native.

Poptocrack
  • 2,879
  • 1
  • 12
  • 28
  • But how to store it in the DB? I store it as a byte array in MySQL and then back to a file when I want to get it back? But I cannot return the data (in the Rest) with images because it´s a JSON like output from the Rest API. The data are posts from users, so I have to return sth. else for react-native? – WindyCode Aug 31 '18 at 18:08
  • Store it to a file in your backend, save the path and convert it to url. Then, save the url in your DB. In the json, send the data that makes sense for you and add a field url_image wich is the file url from your db. You will have to rework principally on your backend. I cant help you with the code. – Poptocrack Aug 31 '18 at 18:32