Y
Y
Yegr02020-09-18 20:44:35
In contact with
Yegr0, 2020-09-18 20:44:35

How to bypass CORS and upload photo to server using VK API?

Good afternoon! I am writing VK miniapps and faced a problem that I can't upload photos to the server.
1. I get the server:

const serv = yield currectBridge.send('VKWebAppCallAPIMethod', {
  method: 'photos.getUploadServer',
  params: {
    album_id: 000, //мой открытый альбом
    owner_id: userId,
    v: '5.21',
    access_token: userToken,
  },
});

2. I'm trying to send a fetch request using this url with a photo that I take from canvas
let formData = new FormData();
formData.append('field1', canvas.toDataURL());
let response = yield fetch(url, {
  method: 'POST',
  headers: {
    'Content-Type': 'multipart/form-data',
  },
  //mode: 'no-cors',
  body: formData,
});


I upload the assembly for production, go to the application and get a CORS block
Access to fetch at ' https://pu.vk.com/c842229/ss2120/upload.php?act=do... ' from origin ' https://stage-app70008-d852483adfb2.pages.vk-apps.com ' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey P, 2021-04-02
@lynxp9

Alternatively, you can send files to your server, and from there upload to VK. But for this you need to have a VK client on the server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question