D
D
dandandan2017-05-22 10:32:02
In contact with
dandandan, 2017-05-22 10:32:02

VK API to upload a lot of photos to an album (restriction is triggered and photos are lost)?

I'm trying to upload photos to an album and then attach them to posts. 10 posts with 5-10 photos per post. VK has a limit of 5 photos at a time. I'm uploading 1 photo at a time, then the next one... Using the code from the last comment from Anonymous Anonymous here How do I upload photos to a VKontakte group album? , slightly modifying it for themselves.
In the loop, I go around the array of posts, then the loop of the array of pictures. I download each one separately. For this I call:

$upload_server = $this->apiRequest('photos.getUploadServer', $data);

I always get a server address like this:
https://pu.vk.com/c637916/upload.php?act=do_add&mid=4488320&aid=244178381&gid=147188527&hash=5c1f8c13c3b1fc0960dca09070a65d39&rhash=89056ea5afaa464efd22821a50df2fd4&swfupload=1&api=1

I'm uploading a picture at this address with a curl. I always get an array like this:
(
    [server] => 637916
    [photos_list] => [{"photo":"ad9c7a5747:z","sizes":,"kid":"6bba8744f1326a9392b95c954925552b","debug":"xszmzxzyzzzozpzqzrz"}]
    [aid] => 244178381
    [hash] => bb87694c04dde19c550fb96c353f6e2b
    [gid] => 147188527
)

Next, I do the Photo.save method, and not all pictures are saved here. The first 5 pictures are saved (for each I use my own save - uploaded, saved). Further, the pictures are not saved, then again a maximum of 5 is saved. I even tried to put sleep(300) between pictures. Still the same.
In case of successful loading, I get an array:
(
    [response] => Array
        (
            [0] => Array
                (
                    [pid] => 456239270
                    [id] => photo4488320_456239270
                    [aid] => 244178381
                    [owner_id] => -147188527
                    [user_id] => 4488320
                    [src] => https://pp.userapi.com/c637916/v637916320/5d25f/8zrcadbGivE.jpg
                    [src_big] => https://pp.userapi.com/c637916/v637916320/5d260/Sqq6-7EgVVo.jpg
                    [src_small] => https://pp.userapi.com/c637916/v637916320/5d25e/lAaBU1AFbgs.jpg
                    [src_xbig] => https://pp.userapi.com/c637916/v637916320/5d261/VKuA8whyUoM.jpg
                    [src_xxbig] => https://pp.userapi.com/c637916/v637916320/5d262/_u7tbmXNTk8.jpg
                    [width] => 862
                    [height] => 624
                    [text] => Экшн-камера Firefly 6S, съемка в 4К
                    [created] => 1495435197
                )
        )
)

If the download is unsuccessful, then the script (and VK) returns nothing - an empty white screen. As I understand it, the VK restriction is triggered. How to bypass it or what timeout to set? It seems to me that 5 minutes is already a big timeout, but it didn't help either.
I'm waiting for answers. Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dandandan, 2017-05-22
@dandandan

Defeated the problem: 414 Request-URI Too Long nginx/0.3.33
Remade the get request for photo.save into a post request.
p.s. Thank you all for your help.

S
sasha, 2017-05-22
@madmages

there is a suspicion that in such a situation you need to re-request the image download server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question