Webservice - RESTful API, Python, Raspberry pi, iOS - web-services

I have a python script that take image using raspberry pi and update a JSON file with id and image URL, which is consumed by an iOS app.(Read Directly the JSON file)
I need a web service that parse the JSON and provide me with only image that is taken recently and return a JSON of new image and id.
so far I can put the code for the web service in the python script used for taking the image and access it using the URL : http://0.x.x.x:5000/application/api/v1.0/image
The above returns a JSON with old and new images and id's
Another problem is, I have to include the port number.
I tried Flask-RESTful for the above.
Is there any ready to use API's that can do this for me, or if I am to write my own web service what is the correct approach.
I have apache server running on the PI, how can I deploy the API and access it using the URL like ://PIAdress/application/Api/image
If there is a better approach please suggest.

Deploy Api to apache2 : example
have two app route : one to get full JSON - application/api/v1.0/image , second to get updated JSON - application/api/v1.0/image/'<'date'>'
get date from JSON and compare with the date from the app - (minus) 10 mins :
add to a list with JSON date that are greater than the compareDate
return jsonify(list) - for json of new image

Related

Appery.io aws S3 integration

Looking for help on how to have a appery.io ionic 5 app upload images, files, videos etc. to aws S3. I am using aws DynamoDB thru API Express successfully and can get a presigned S3 URL thru API Express as well. My problem is using the presigned URL to upload a image/file. Tried fetch, httpClient etc. Some Guidence would be greatly appreciated.
Thank you
To work with binary data in API Express you can do the following:
Create new service of Custom REST API type
In START node select POST method and Binary for request body
With that you should be able to select Binary request as parameter value in SQL node
The second part of the question is how can you get the binary data if you have fileUrl.
Import API Express service created on a previous step into your project with Create New > API Express service
On Code tab create a variable named buffer of type Any
On Data tab add datasource for the imported API Express service. In Before send mapping connect buffer with body.data
Drop the button on Screen1
Add event with TypeScript code to it:
fetch(fileUrl).then(res => res.arrayBuffer()).then(arrayBuffer => {
this.buffer = arrayBuffer;
this.Apperyio.execDataService(this, "myAexService");
});

Rendering images from REST response on localhost

I am trying to run a REST API on one port (8000) using django and consuming that API in an App running on port 9000 again using django.
My REST response is having an image field, now the problem is that i can not provide my desktop path in upload_to option in my API models and if i am giving the absolute path of API project in my App project index. Html, i get a browser error as "Not allowed to load resources from local path"
So i am having to create media folders with same name in both API and App projects and keeping image files in both and using only the file path from the REST response and rendering the image from App project itself.
Is there any way i can get away with this and consume the image from the Rest response only?
You need to convert image to base64 in server side then send those base64 string as response . Then consume this base64 string as response in calling api. Then use it accordingly either save in filesysyem or in database . But make sure to converse base 64 image string to bytes.

Microsoft Cognitive-Speaker Recognition - Verification profile - Create Enrollment

I am trying to make a call in Postman for the Microsoft Cognitive Service - Create Enrollment for Verification profile.
This is what I am using: https://westus.dev.cognitive.microsoft.com/docs/services/563309b6778daf02acc0a508/operations/5645c3271984551c84ec6797
I have an API URL created: https://internspeaker.cognitiveservices.azure.com/spid/v1.0 And the Subscription-Key.
I started by using their testing console and all of them worked perfectly until the enrollment process where I have to add an audio file in a specific format (.WAV with different characteristics). The Microsoft console asked me for binary data for the audio file and I could not get the audio file converted. So I found another way of testing by using Postman.
I took all other processes and they worked perfectly until I tried Create Enrollment for the Verification Profile. Here I added all the details + the audio file but I could not pass the error(the error is shown in the next link)
This is the error I am getting:
This is how I added the audio file in Postman:
This is a successful call with the same URL and subscription-Key:
Does anyone know how to deal with this problem?
Thank you very much
Your url is not in right format.
Your url should be https://internspeaker.cognitiveservices.azure.com/spid/v1.0/identificationProfiles/{your identificationProfileId}/enroll. You could find the success url format is correct.
And your way to add audio is fine.
Update:
if want to use verification profile to create enrollment, the url should be:https://internspeaker.cognitiveservices.azure.com/spid/v1.0/verificationProfiles/{your verificationProfileId}/enroll.

HighCharts doesnt get data from Flask endpoint

I use the code of "Live data from dynamic CSV" from Highcharts Demos as a basis for my need. As it gets data lively from a web service url, I just change it to get data from my Flask endpoint. That is to say, I use the same code to be served with Flask.
Even if the flask endpoint serves the same content, I don't get it to work. I just changed the url of "https://demo-live-data.highcharts.com/time-data.csv" with /data. And here /data serves the totally same kind of csv output.
So far I could not obtain the result.
Demo code located in "https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/demo/live-data/" is used.
var defaultData = '/data';
I found out that I have to use "http://10.0.2.2:5000/data" instead of "0.0.0.0:5000/data". Because 10.0.2.2 is the special alias to host loopback interface (aka 127.0.0.1).

RESTful webservice API : how to handle a web URI route for a 100 music files

I am a totally newbie to the world of REST API. from what I have read and I think I understand 2 main things .
1) REST uses the the same HTTP methods (GET PUT etc) for a specific resource on the server.
2) Every resource on my server must be accessible from a unique URI.
So Combining 1 and 2, I can send a HTTP request to send a resource URI (eg. Radio.com/Music/1 and a GET request which will then fetch Music song 1).
Now I have a simple HTML page which has links to 100 Music files on the server. The idea is that the client will click on a link and then Should be able to play/download the music file (I am not so concerned about the how part related to audio). So the server must provide the links to each Music file eg: Radio.com/Music/1 .
My Question:
Q1) In this way must the should the client be exposed to each and every URI for the resource. So When the hosting the html page should i put these links individually for each music file link
Q2) We need to have a route to each and every resource for the 100 music files on the server . If I am doing in Sinatra like do I need a do route for every of the 100 music files ?
Something link '/do' /Music/1 , '/do' /Music/2 and so on
(Isn't this cumbersome and if I add another 100 music files , then I need to add another 100 routes in Sinatra).
Is this how the REST API would work, or have I totally got it wrong?
Imagine you have two servers.
First server is your api server: http://api.yourhost.com/v1/... (java, node.js, etc...)
This REST-server will return a simple json response:
{
"base_url" : "http://static.yourhost.com/music/",
"tracks" : [
{
"name" : "track1",
"file_name" : "track1.mp3"
"file_size" : "3.43MB"
},
{
"name" : "track2",
"file_name" : "track2.mp3"
"file_size" : "6.12MB"
}
[...]
]
}
The second server: http://static.yourhost.com/ is your content delivery server (apache, nginx, etc...)
The idea is, that your api REST server should never send binary data like audio or image. It sends json/xml only.
You can also send the full url for every audio file, but this information could be redundant.
ad 1)
When the hosting the html page should i put these links individually for each music file link
If you take REST seriously and if you see this HTML page as a representation of the collection resource of all music files, you should do this. One basic mechanism of REST is links for the client. The client should be able to just follow links without having to build them himself.
ad 2)
We need to have a route to each and every resource for the 100 music files on the server.
Every library that implements a RESTful server is able to have routes with path paramters. Usually such a route is defined using a pattern like
/Music/{id}
where {id} is the path parameter. The code that is bound to this route will then have available a variable named id. Using this approach you need only one route.