-1

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?

I am a Student
  • 1,570
  • 4
  • 21
  • 36
kepler92
  • 9
  • 2
  • Have you read the documentations on django-forms: https://docs.djangoproject.com/en/2.0/topics/forms/ – Shameer Kashif Mar 17 '18 at 10:28
  • Does the host expose a REST API? How do you interact with the host? – Will Keeling Mar 17 '18 at 17:52
  • @ShameerKashif Yes, but that topic not found. – kepler92 Mar 18 '18 at 04:40
  • @WillKeeling I have to send an image to a well-decorated web page with django that I called host. I want just send image using rest api. But, Google search did not show how to send data to the image field of another django web page via the data in the image field. – kepler92 Mar 18 '18 at 04:43

1 Answers1

0

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

Will Keeling
  • 22,055
  • 4
  • 51
  • 61