A
A
Alex2019-09-23 14:16:00
JavaScript
Alex, 2019-09-23 14:16:00

Is it possible to send a blob file from JS to VK servers?

Actually a subject. Is it possible to send a file directly from the application using JS to the URL received by the docs.getUploadServer method, for example. Now I have found only one way out, this is to send the Blob file to the server along with the URL and the user's token, and from there send it to the VK server using cURL.

Perhaps someone has implemented something like this or is it not possible due to the limitations of JS and VK?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GrayHorse, 2019-09-23
@GrayHorse

Probably, my answer is not what you need, but since it’s already empty here:
I don’t know what is under the application, but it’s File that needs to be sent, not Blob (although it can be used for uploading images). File is the same Blob, with two additional fields.
For example, JS code:

url = "https://pu.vk.com/...";

(async (url) => {

    const formData = new FormData();

    const blob = new Blob([new Uint8Array(1 * 1024 * 1024)], { type: "text/plain" });    
    const file = new File([blob], "qwerty.txt");
    
    formData.append("file", file);
    
    console.log(await (await fetch(url, { method: "POST", body: formData })).json());
    // { file:  "..." }

})(url);

Only in the browser it will not work, because. CORS. (Or it will be if you run a script (extension) as a content / background script)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question