Here's what I'm trying to accomplish:
After user takes a picture with the android camera, I want to save the image onto my Ruby on Rails web application (like PicPlz or Instagram)
Approach 1: After user takes the picture, convert the byte array and save as .jpeg on the phone. Then upload the image file onto the server through a post request (Link here)
Approach 2: After user takes the picture, post the byte array data directly to my web application's web service, and then have the web application convert the byte array into an image file and save it onto the server
Question: Which approach is faster and more efficient?
I'm also open to suggestions for other approaches.
Thanks for your time and help :)
The answer is inexplicably the server, especially if you can get Image Magick installed on the box and convert the stream from the command line. I use PhP, but to my understanding running commands from Ruby is very similar and easy.
The phone... nine times out of ten is going to be running a whole lot of background apps and you will never be able to rely on it to do anything quickly. People install garbage on their phones and never clean it up just like they do there PC's and Laptops.
Approach 2 is better.
There is another approach that u can take.
- store the byte array into a temp file before u start sending it to the server.
- This makes sure that u don't lose the data even if there's a problem with the connection.
- Once the upload is complete, ur application can erase the temp file.
- One more advantage of this approach is that u can make sure that the user can make use of ur application, even when they are not connected to the internet.
- Once the user is connected u could ask them, n then start uploading to the server.
Related
I have a simple phototaking android app that allows the user to take a photo and save it. I allow the user to create multiple versions of the photo in the app - adding captions, filters, etc. After the user is finished, I upload the photo to Firebase storage. Here I upload a few files
The original raw bitmap that was taken using the camera
The finished bitmap with all edited captions and filters applied
The thumbnail of the the raw bitmap, and finally
The thumbnail of the finished image
The thumbnails and the full size images allow users to undertake future interactions with the app.
What would be the most efficient way to upload the images? Options that I know of are
Using 4 different upload tasks from the Android app. But this is taking a few seconds to finish all 4 uploads.
Using 2 upload tasks for the fullsize images and then using Firebase 'functions' to create the the thumbnails in the server. However, I would need to create the thumbnails locally in the app for display purposes before uploading, so it would mean creating the thumbnail in 2 places - app and the server. Also it would mean doing double error handling - one at the server side and the other on the app end.
Is there any other option?
Looking forward to whatever help I can get. As usual, feel free to ask for clarifications, via comments.
That depends on your scenario. If you are on "Spark" plan then using firebase functions too much might exceed your free quota of:
Invocation (125K/month)
GB-seconds (40K/month)
CPU-seconds (40K/month)
But if you can upgrade to "Flame" or "Blaze" then it won't be an issue and its the preferable way.
On the other hand, thumbnail file aren't too big that takes much time for uploading, unless you are on extremely slow connection, then uploading thumb files from app won't be an issue. You might not even notice the uploading time. It will be quick.
I have two application need to transfer data together using intent. I get problem with transfering large data - pictures, as it is limitted in android.
My first app stores picture as binary data in database (no local path existing). Now I want to transfer this picture to the second app (which impossible using intent as big).
Does someone give me an advice to solve this problem?
I have an idea that my second app will read directly from DB.
Is it possible? Any example is appireciated.
Thank you.
This case you have to use ContentProvider, which allow you share data provider for your first app to the second.
This is a good link for you: http://mrbool.com/android-content-provider-how-to-use-content-provider-for-data-access/30446
As explain in the Google documentation, it's the mechanism in use to get Picture from the PictureGallery of Android, so I presume this approach is the best available on Android platform.
I am making a network app that works with a few news sites. I have an option to view and download articles (for reading in future). There is no fast mobile internet in my country (mostly 2G with the speed up to 15 KB/sec) and my app doesn't work really well with the slow connect though it's perfect with fast connection. As I have seen from logs it can't establish the connection. When I try to open the article it doesn't load at all or goes into infinite loading. When I try to save the article it simply saves the blank file. How can I track these mistakes and catch them? And what are the correct ways of handling it?
I suppose that my code is irrelevant as it works correctly with Wi-fi. I think I simply need to add lines, not to edit them
ok, you need to manage the information very good, you need define the package size to download, you need a webservices that allow to you to manage the information one by one, for example you need design packages no more than 500kb size to download, when this package is downloaded you can show something in your mobile and continue downloading the next package in background.
500kb is only an example you need to test what is the maximum data size to download and create packages like that in your web services
I have an app that gets data from web api.
I am returning some info and image from web api. I have 2 options for image and these are:
Return image link(web address) and download it with async task.
Return image in base64 encoded string.
I would want to know which is faster and better idea?
Thanks.
I would say this depends on the way your application is workingand what it needs,
The data itself is the same, so just think what would fit your app better,
I'll give some examples:
If the web api returns many responses with the same image and different info, you might want to use another server so you could use caching systems / cdn and than better perform your app
If it would help you that the "info" will reach to the app before the image (so you could load it first), you should also use the first option, and when the async proccess ends display the image (just an example...)
If you want to spare computing resources from the api servers every time it is used (encoding the image to base64 ect..) you should also use the first option
If lets say, you want to make sure that all the data comes at-once and non of the above is relevent to you, maybe you would prefer the second option
If you want to avoid async requests or having multiple requests every time may be the second option is better for you too
So, its just up to what your app needs :)
Hope i helped
I am developing an application where it should get data from my server with respect to the ID Number , and also I need to take an image from database , according to the id number. So I went to an option of loading url image. There I could not able to get large size images. So I went to converting the image to base64 format and sending it through webservice. Even in that I was able to retrieve small size strings , but when I go for big size of images, the base64 string is bigger. So looking for possible answers, any way thanks in advance...
Sending photos in binary form over a HTTP connection is a solved problem. I suggest you go with an off-the-shelf web server and call it a day. To send reduced-size images, install a script that (in response to a URL that indicates desire for a thumbnail) will check for thumbnails; create them if they don't exist; and then serve as images in the standard manner. Don't worry about base64 unless you're dealing with really ancient services that don't understand pure binaries. If you do go the route of base64, don't worry about file-size expansion. Unless you're sending huge numbers of images, it's not that significant.
I had this problem and had to use ftp server. I put my image files into a ftp server and download each one I need.