Answer the question
In order to leave comments, you need to log in
POST request
Good day. Please tell me how to send a .jpg file using the POST method from your page to a certain url using HttpRequest in javascript.
PS: I would be very grateful for an answer in the form of a code, because in theory I can imagine how this is done, but I cannot implement it.
PPS: Or tell me how to send img along with the form using the POST method.
PPPS: Or tell me how to send a POST with a .jpg file using Pyton.
Answer the question
In order to leave comments, you need to log in
The browser won't let you do that. But you can upload this file to an intermediate (your) server, and from it at least send it with curl to its destination.
You can even make a "transparent" sending using websockets.
something like this . encode the image in base64 and send the string to the server, and then decode it back
Let me google for you
From the server.
Python:
# --------- upload_file.py ----------------
# upload binary file with pycurl by http post
c = pycurl.Curl()
c.setopt(c.POST, 1)
c.setopt(c.URL, "http://<кудахотитеслать>")
c.setopt(c.HTTPPOST, [("file1", (c.FORM_FILE, "c:\\tmp\\download\\test.jpg"))])
#c.setopt(c.VERBOSE, 1)
c.perform()
c.close()
print "that's it ;)"
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_URL, 'http://<кудатамнадо>');
curl_setopt($ch, CURLOPT_POST, true);
// same as <input type="file" name="file_box">
$post = array(
"file_box"=>"@/path/to/myfile.jpg",
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
java script works only on the server side, so no way. and why are you sure that this certain URL will accept your image?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question