django send image filed oher rest api - django

I am using Django.
[My web application structure]
I have implemented the structure shown in the picture above
But I have a problem.
There is no problem with images send between clients and bridge hosts.
However, I am not sure how to send an image between the host and the bridge host.
How should I send it?

You probably want to send the image to the Host's REST API using a library such as requests.
On the Bridge Host in the view that receives the file from the client, you will need to get a handle on the file:
# Get the file sent by the Client
image_file = request.FILES.get('name_of_file')
Then you'll need to post that file to the REST API end point of the Host.
# Post the file to the Host from the Bridge Host using "requests" library
requests.post('/Host/image/endpoint/url', data={'name_of_file', image_file.read()})
You will need to pip install requests on the Bridge Host if it is not already present.
More info about making POST requests using requests: http://docs.python-requests.org/en/master/user/quickstart/#post-a-multipart-encoded-file

Related

How to use Postman to send request to another PC's server?

I have an Rest Api created on my destination PC. I can make post request to localhost using postman from same PC. but I want to send a post request to the localhost of another machine. What steps do i have to take to achieve this?
To do so, you need to have both pc on the same local network if you want to test locally.
Use the other PC's(where REST API is deployed) IP or hostname to hit the REST API request.

Not able to connect Node.js/Socket.io Server from a Client using Websocket from a Unix System in a LAN

I have written a client application in C++ using websockets in Unix Environment trying to connect a Node.js/Socket.IO server running in a LAN connectivity. I found the server application is not responding at all. I tried a couple of other options from client side eventually getting no response from the server. Basically, i am trying to send a JSON object to the system running SocketIO server, but the client is not getting connected even if the server listens on to a Port.
Help, is really appreciated. Thank you.
Make sure following has been checked-
Server running and port is open (firewall) - Client is unable to connect the server
Url is correct - Client is unable to connect or url not exist
Listener code or receiving task is running - Client connected but when server send data to client, client didnot receive data
JSON format is correct and json data does not contain invalid character - client send data server but server did not received
Follow -
remove date if exists into msg for test purpose, use " to prepare JSON data, donot put / end of the url if not required. example-
1. Write url as ws://abc.com:8080/wsserver
2. JSON data as {"name":"myname","yourname":"indo","msg":"birthday"}

Handle request over TCP connection using django

I'm developing a server using django. There are numbers of devices that connect to this server and send request periodically. How can I handle these requests properly?
You'll probably want to look into django signals to setup webhooks to listen for certain things to call other things etc... signals was built to keep your app in sync with changes being made throughout. https://docs.djangoproject.com/en/dev/topics/signals/

How to set header/cookies for Titanium Network Socket TCP?

I'm trying download a image file from remote server using Titanium.Network.Socket.TCP.
Server requires header/cookies, how to set cookies?
In HTTP requests, you can use the method setRequestHeader to include your header information.
For example:
xhr.setRequestHeader("X-Auth-Token", "foobar");
Docs: http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.Network.HTTPClient-method-setRequestHeader

How do I copy a file on a http server, from the client?

In the past I used an ftp server, connected via "ftp" from the client and "GET" to copy one file from the remote machine to the local machine.
Is it possible to do the same but with the server only running a http server?
Server: GoAhead Web Server.
Both client and http server on Windows.
The copy can be either initiated from the browser or if need a separate program can be written on the client. (i.e. - any windows api calls to copy a file from http server?)
(Also, the files may not be in the http root web directory but somewhere else on the server....can that happen?)
HTTP servers will only serve up files that are located within the site's document root. If you want to get at files that are outside the document root, you'll have to have a script serve up that file from the server (php, perl, cgi, etc...), or find some way of getting that file "inside" the document root.
To download files within the site's document root, you just hit a url pointing at that file - that's the core point of HTTP - you're just downloading content from the site.
HTTP servers will also not accept uploads without an intermediate script to handle it. If they did, you could upload any file you wanted to any server, anywhere.
What others mentioned about HTTP servers is true, but GoAhead Web Server is not a only a HTTP server. It provides many other features on top of that. And file upload seems possible, with help of a patch. More info:
https://embedthis.com/goahead/
Use WebDav for this purpose.