I am trying to upload a photo to VK through their api. Here is my code:

let image = UIImage(named: "vk")! let data = image.pngData()! let site = URL(string: "https://pu.vk.com/c****/upload.php?*****....")! //<= Ссылка для загрузки фотографий в альбом upload(multipartFormData: { (multipartFormData) in multipartFormData.append(data, withName: "imagefile", fileName: "image.jpg", mimeType: "image/jpeg") }, to: site) { (encodingResult) in switch encodingResult { case .success(let uploadRequest, let streamingFromDisk, let streamFileURL): print("success") print(uploadRequest) uploadRequest.validate().responseJSON() { responseJSON in switch responseJSON.result { case .success(let value): print(value) case .failure(let error): print(error) } } case .failure(let error): print(error) } } 

The console displays the answer:

 { aid = ******; hash = ******; "photos_list" = "[]"; server = *****; } 

The photo_list is empty, although it should contain information, for later saving the image of the image in the VK album. Tell me what am I doing wrong?

    1 answer 1

    The issue is resolved. It is necessary to name the photos as follows file1, file2 ... file5 (5 maximum). Here is the fix

     upload(multipartFormData: { (multipartFormData) in multipartFormData.append(data, withName: "file1", fileName: "image.jpg", mimeType: "image/jpeg") }, to: site)