def uploadPhoto(self, photoLinks, albumId, groupId = None):
if len(photoLinks) > 5:
print("cant send more than 5 imgs")
return
query = {
'album_id': albumId,
'access_token': self.token
}
if groupId is not None:
query['group_id'] = groupId
res = requests.get('https://api.vk.com/method/photos.getUploadServer', params=query)
res = json.loads(res.text)['response']
uploadUrl = res['upload_url']
files = {}
for i in range(0, 5):
res = requests.get(photoLinks[i])
filename = 'tempfiles/output{}.jpg'.format(i)
with open(filename, 'w') as f:
f.write(res.content)
file = open(filename, 'rb')
files['file{}'.format(i)] = file
res = requests.post(uploadUrl, files=files)
for file in files:
file.close()
res = json.loads(res.text)
return res