Saving an image for image recognition via REST on raspberryPi - android

I am doing a project for image recognition. I want to send an image or a video from an android app to the raspberryPi, that is my server (I use flask), and make the recognition on the server and then send back the result to android. I want to do this with REST and python. So how can I do this?
I am new to all of this so any help is really helpful!

Yes, as your raspberryPi server use flask, so you can done the task through HTTP and your android phone browser as client.
raspberryPi as server should have the following api:
Chose a image and upload, then recognition and send the result back.
That all.

Since you are using flask, you need to implement REST endpoint that handles multipart/form-data, the example of such endpoint you can find here.
On the client part (in your case - android app) you need to implement sending of the image to that endpoint, example you can find here.

Related

Detect device/app on Rest call

I have a rails project whose API's are used by two different but related apps.
One app (Parent) is made using Unity, while other one (Child) is with native (iOS & Android).
In case of error response.
Unity app requires 2xx series status code,in case of any other status code they read it as success case.
While native (iOS & Android) apps need 4xx series status code, in case of any other status code they read it as success case.
Is there any way that from request I can know that which app sent request?
or any other solution to handle this?
Is there any way that from request I can know that which app sent
request?
Yes. Several ways.
1.Use form to send which device is making the request then access this fro your rail server.
WWWForm form = new WWWForm();
//From Unity
form.AddField("App", "Unity");
Or
//From Native
form.AddField("App", "Native");
Then send:
UnityWebRequest uwr = UnityWebRequest.Post(url, form);
yield return uwr.SendWebRequest();
2.Use a custom header to send which device is making the request then access this from your rail server.
//From Unity
UnityWebRequest.SetRequestHeader("App", "Unity");
Or
//From Native
UnityWebRequest.SetRequestHeader("App", "Native");
All you need to do is access "App" on rail for both of these.
3.Use json or xml to store which device the request is coming from the access this from the server.
The API used here is for Unity but you can do similar thing on iOS and Android too for the native app with Object-C and Java API. It's still the-same thing.
request method has parameter as
request.user_agent

Res.redirect() vs res. Json(). Server for web and mobile

I am new to web development. I had a web project with EJS templating. It redirects directly from the server. Using res.redirect() . I want to create a server for web and mobile both.
Question is... When i use res.json() it sends JSON data to client side. Can work for both.
It is possible to use res.redirect() for both. Web and mobile.
Pros and cons of res.rediret and res.json
Please explain. I appreciate your suggestions in adv. Thanks.
It is possible to use res.redirect() for both. Web and mobile.
If you mean can you use res.redirect() as an alternative to res.json() then the answer is NO. res.redirect() is not an alternative to res.json. res.redirect() only sends a code and a URL back to the client, there is no data in the response. You will still need to use res.json or res.send to get the data you need. Every time you use res.redirect() you are sending a response to the client telling them to make a brand new request to another location. You're not sending any real data. The android app will not get any content till you use res.json or res.send. Redirects just tell the client go get the data from somewhere else.
Below are example responses to an android app when the server uses res.json and res.redirect
res.redirect("/user")
//Response to Android app
302 /user
The response above means what you want is located at "/user" so the mobile app will need to make a request to
res.json(user)
//Response to Android app
{
name: "Arpit Yadav",
phone: 555-555
}
res.redirect sends status code 302 (if not specified), and location (route) to browser, after which browser redirects the request to the specified location, whereas res.json sets Content-Type: application/json and sends data to the browser.
Redirection is generally meant for browser only, but, you can use it for mobile. In that case, you have to handle the logic to re-request with updated location received from server that is not recommended.
In nutshell, both have different purpose. res.redirect to move clients to different route and res.json to actually sends the data.

How to send JSON string from arduino to android device in terms of response and then decode the string on the android application?

I am currently working on a project whereby i need to send a request from an android application to my Arduino mega which in turns response back with the states of LEDs connnected to the Arduino. I have already implemented the GET request. However i need to know how to read the response back and how to send the string from the Arduino to the Android app.
Here is the code for the response:
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: application/json");
client.println("Connection: close");
client.println();
client.println("{\"status\":\"ok\"}"); // <--- how to create the string?
and also how to decode it from the android application. I have seen tutorials on the internet about using InputStream to do so but am unable to understand the code. Could you please help me on this.
You have to implement a Webserver on Arduino side and use a HTTP library (i.e. OkHTTTP) to connect to the Webserver.
I used OkHTTP on Android side but you could use other libraries too.
This link is something like you are looking for. It is from my blog.
Otherwise you can use aRest. It is very simple to use. If you want to know more give a look at this link from my blog.

Android cannot communicate with localdjango server?

I am trying to post data from my client android application to a django server.
for example I have User {login:---, email:---} and I wanna post them my LOCAL SERVER based on django.. what I should do ? any link or tutorial can be greatful, i can't find any thing really helpful.Thks
You need to make a HTTP request to your django server. Here is a similar question how to do a post request in android

How to retrive Image from client on jaxrs webservice

I m using phonegap to bulid an application.I m using cordova 1.9.0.js .In the application I need to send images to the server. I m using the code avialable here for the client side:
http://docs.phonegap.com/en/1.0.0/phonegap_file_file.md.html#FileTransfer
The code shows correct number of byte sent in client logcat indicating that the file transfer was successful.
How will I recevie the image at server side. I am using restfulwebservice based of jaxrs on serverside.
Please help regarding the topic as i cannot find anything.
Thanks

Categories

Resources