React Native Image Fetch/Upload - java

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?

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.

Related

Upload images without convert to string

I need to upload images and i want to show all of images in another page. I have tried to use volley, but it need to encode and decode to show all images. It made my application not responding when i decode all the string of images.
My questions are:
Are there any ways to upload images beside volley?
Are there any ways to upload images using volley without convert them to string (encode)?
Thanks
I implemented it once by positing multi part file using HttpUrlConnection.
Basically you provide the image file input stream, the desired file name and the file's MIME type.
You can access the source code through this link:
https://github.com/MinaSamy/DailySelfie/blob/master/app/src/main/java/bloodstone/dailyselfie/android/utils/PostMultiPart.java

Picture upload and download to google appengine is slow

I am storing pictures in the google datastore that have the size of around 450 x 450 pixels but download speed and especially the upload speed is very slow. Around 5 -15 secs.
In my android app I transform Bitmaps to byte arrays and the byte arrays to a Base64 encoded String which is stored as a Blob in the datastore. For download I do the same the other way around.
I checked the appengine latency but its quite fast about 150ms. So i guess the problem is somehow the bandwith speed...
Does anyone know if this is normal for that picture size? And is it maybe the wrong way how I transform the pictures?
What are usually the techniques to send a bitmap fast?
Thanks for any help!
Edit
I am using google cloud endpoints
Sending files as byte arrays in JSON services and storing the files in the datastore are both pretty bad practices. You should use the BlobStore to upload the images and then use the images service to get a serving URL for the image you uploaded. Store the blob ID and URL in the datastore and whenever you want to view an image in the client - load it directly from Google's CDN by fetching the URL you got. Both upload and download will be orders of magnitude faster this way and even cost you less.

how to compress json in php and decode in android

I am developing an app which sends may be like 400kb of data in the interval of every 5seconds ,i have read somewhere that we can conpress the data in php using gz but how to measure the compression and how to deconpress it in java /android .

Displaying Blob from App Engine Datastore as an image

I have an App Engine Connected Android Project, so I am using endpoints. I ultimately converted the bitmap from my Android project into an encoded string to use in my setter, where I converted this string back into a byte array and then to a Blob, and then persisted the blob to the datastore. I know when to retrieve this Blob and display it as the actual image on the app engine front end. How can I do this? I'm a very beginner, especially with using Blobs.
As stated in the official docs.
If you are serving images, a more efficient and potentially
less-expensive method is to use getServingUrl() using the App Engine
Images API rather than blobstoreService.serve(). The getServingUrl
method lets you serve the image directly, without having to go through
your App Engine instances.
So basically having a blobkey you can use
ServingUrlOptions options = ServingUrlOptions.Builder
.withBlobKey(blobKey);
String url = imagesService.getServingUrl(options);
And access that image as "static" content hosted by Google without going through your server.

Fetch Image and Save To Google App Engine Using Blob

I have image URLs like http://example.com/someimage.png - how do I fetch that image and save it with Blob? Thanks.
Here's example code from the documentation showing how to write a file to the blobstore. You'll have to use a stream instead of a writer, since a PNG image is binary, and you'll have to set the appropriate content type, but it should show you the way.
And here's the UrlFetch documentation, explaining how to get some available resource on the web, using HTTP.

Categories

Resources