T
T
TERMIK2012-01-17 23:07:50
Python
TERMIK, 2012-01-17 23:07:50

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

7 answer(s)
E
Eddy_Em, 2012-01-18
@Eddy_Em

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.

H
himik, 2012-01-17
@himik

something like this . encode the image in base64 and send the string to the server, and then decode it back

V
Vitaly Zheltyakov, 2012-01-17
@VitaZheltyakov

No, it's not possible.

M
m00t, 2012-01-18
@m00t

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 ;)"

MARKET:
<?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);

M
Maxim Khodyrev, 2012-01-17
@maximkou

java script works only on the server side, so no way. and why are you sure that this certain URL will accept your image?

H
Homakov, 2012-01-18
@Homakov

html5, pluginload

T
TERMIK, 2012-01-19
@TERMIK

Thanks to all! Here is the answer www.netfaq.ru/ajax/ajax_post_request

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question