Answer the question
In order to leave comments, you need to log in
How to upload an image to the VK server for further publication on the wall?
Following the instructions from the VK API, I got the address of the server, which will receive the image in the future.
Next, you need to form a POST request with the upload_url and photo fields in the multipack/form-data format . And at that moment, everything stopped. Whatever I try, the server sends an empty array instead of the photo field. Help me please!
Answer the question
In order to leave comments, you need to log in
There is a program for making HTTP requests. It's called Postman. In it, you can visually form a request and generate code.
Here is an example curl request:
curl -X POST \
'https://pu.vk.com/<ссылка загрузки>' \
-H 'content-type: multipart/form-data;' \
-F [email protected]/private/tmp/f.png
import http.client
conn = http.client.HTTPConnection("pu,vk,com")
payload = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"photo\"; filename=\"f.png\"\r\nContent-Type: image/png\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--"
headers = {
'content-type': "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
'Cache-Control': "no-cache",
'Postman-Token': "78ca70c7-7da5-45c7-8a79-67d79d09761c"
}
conn.request("POST", "", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question