N
N
Np1029012017-05-31 19:11:51
JavaScript
Np102901, 2017-05-31 19:11:51

How to upload an image to VK using JavaScript?

Generally. There is an image, can it be uploaded to VK to the user on the wall or in a separate album (no matter where) using Javascript ? Please describe in more detail. If not difficult)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2017-05-31
@sergiks

From the browser directly to VK will not work . From nodejs or Electron - easily.
The key point here is the response of the VK server to upload a picture file to them. They respond without CORS headers and the browser considers such a response unsafe, making it inaccessible to JS scripts.
Uploading files to VK is well described in their documentation . Three steps:
All this is easily done in JavaScript, but the security policy of browsers does not allow receiving a response from a foreign server if it is not accompanied by special HTTP headers. And VK does not give them for some of its own “security” reasons, as their technical support answered me:
Therefore, you can only upload through your own server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question