I upload a photo to my album according to the documentation :
authorization procedures, getting album id, download addresses are omitted, because work correctly
button.addEventListener("click", function () { var formData = new FormData(); formData.append('file1', file.files[0]); let xhr = new XMLHttpRequest(); xhr.open("POST", upload_url, true ); xhr.onload = xhr.onerror = function() { let data = JSON.parse(xhr.responseText); console.log(data) }; xhr.setRequestHeader('Content-Type', 'multipart/form-data'); xhr.send(formData); }); <input type="file" id="file"> <button id="button">OK</button> However, in the response from the server comes an empty property photos_list:"[]" which makes it impossible to further save the photo. A long and persistent googling did not lead me to anything other than the information that the empty photos_list property indicates that I am not transferring any files to the server.
However (in my opinion) I act according to the documentation. Below are the headers of the POST request itself:
Request URL:https://pu.vk.com/c636925/upload.php?act=do_add&mid=12591728&aid=221386829&gid=0&hash=092d7aa4авыgad01d984ebaca84cf6159dcfb85&rhash=b2771b5f5g6b6f40asd304e239e46574076cb3&swfupload=1&api=1 Request Method:POST Status Code:200 Remote Address:87.240.165.92:443 Response Headers cache-control:no-store content-encoding:gzip content-length:105 content-type:text/html; charset=windows-1251 date:Tue, 21 Mar 2017 10:17:09 GMT pragma:no-cache server:nginx status:200 vary:Accept-Encoding x-powered-by:PHP/5.4.45-0+deb7u2 Request Headers :authority:pu.vk.com :method:POST :path:/c636925/upload.php?act=do_add&mid=1259321728&aid=2216386829&gid=0&hash=092d7a4asdgf01984ebaca84cf6159dsdcfb85&rhash=b2771b5fasd56b6f4d0304e9e46574076cb3&swfupload=1&api=1 :scheme:https accept:* accept-encoding:gzip, deflate, br accept-language:ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4 content-length:4469 content-type:multipart/form-data origin:http://evil.com/ user-agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36 x-compress:null Query String Parameters view source view URL encoded act:do_add mid:12591728 aid:221386829 gid:0 hash:0s92d7aasd4a0hh1984esgfbaca84asdcf6159dacfb85 rhash:b2771bgh5f556fghb6f403304e9h4fe346574076cb3 swfupload:1 api:1 Request Payload ------WebKitFormBoundarynspHTlbJ4EXApLsK Content-Disposition: form-data; name="file"; filename="128x128.png" Content-Type: image/png ------WebKitFormBoundarynspHTlbJ4EXApLsK--
formData.append('file1', file.files[0]); formData.append('file2', file.files[1]); formData.append('file3', file.files[2]); formData.append('file4', file.files[3]); formData.append('file5', file.files[4]);formData.append('file1', file.files[0]); formData.append('file2', file.files[1]); formData.append('file3', file.files[2]); formData.append('file4', file.files[3]); formData.append('file5', file.files[4]);`The Request Payload itself contains the request: ------ WebKitFormBoundarynspHTlbJ4EXApLsK Content-Disposition: form-data; name = "file"; filename = "128x128.png" Content-Type: image / png ------ WebKitFormBoundarynspHTlbJ4EXApLsK-- - Loosefer