0

Trying to handle response from Alamofire but response is multipartFormData and i cannot parse it. I have no problem about make request. As i check service logs i can correctly send my request in multipartFormData and receive true response also in multiparFormData. Alamofire give me responses like response.result, response.data, response.value but none of them help me. There is a something like Json part and also wav file in response and i need to take them separately. (By the way parsing it like a json is not working, response is not json. ) Here is my code;

Alamofire.upload(multipartFormData:{ multipartFormData in


    multipartFormData.append( (jsonString?.data(using: String.Encoding.utf8)!)!, withName: "Json")


    if let resourceUrl = Bundle.main.url(forResource: "Path", withExtension: "wav") {
    if FileManager.default.fileExists(atPath: resourceUrl.path) {
                    print("file found")
                    multipartFormData.append((resourceUrl),withName:"AudioForSr")

                }
            }

        },
       usingThreshold:UInt64.init(),
       to:"http://192.168.10.***:30***/***/***/**/Run",
       method:.post,
       headers:["Authorization": strToken],
       encodingCompletion: { encodingResult in
        switch encodingResult {
        case .success(let upload, _, _):

       upload.responseString { response in
            debugPrint(response.result)
            debugPrint(response.data!)
            debugPrint(response.response)
            debugPrint(response.timeline)
            debugPrint(response.value)
       }

    case .failure(let encodingError):
        print(encodingError)
    }
})

debugPrint(Response.result) output is

SUCCESS: --38596e3e-346b-4d0d-8344-408ed12d99bf

Content-Type: application/json; charset=utf-8

Content-Disposition: form-data; name=Json



{"Type":"message","Id":null,"Timestamp":"2018-01-10T10:04:49.6035939Z","ServiceUrl":"localhost","LocalTimestamp":null,"ChannelId":"Skype","From":{"Id":"123","Name":"Jane ***"},"Conversation":{"IsGroup":null,"Id":"7bb20efb-43a2-44aa-b041-89dd4187284e","Name":null},"Recipient":{"Id":"555","Name":"John Doe"},"Locale":null,"TextFormat":null,"Text":"Peki hangi demomuz ile devam etmek istersiniz?","Speak":null,"Summary":null,"AttachmentLayout":null,"Attachments":[],"Entities":null,"ChannelData":{"ProjectName":"","AudioOutput":{"Generate":"true","PutInStructuredPart":"false","ExpectedFormat":"audio/wav"},"GenerateChatOutput":"true"},"ReplyToId":null,"Code":null,"IsSuccessful":true,"ErrorCode":"","ErrorMessage":""}

--38596e3e-346b-4d0d-8344-408ed12d99bf

Content-Type: audio/wav

Content-Disposition: attachment; filename=AudioFromTts.wav; name=AudioFromTts

Content-Encoding: binary



RIFFp»\277´ÿ¦ÿªÿ®ÿ¦ÿ¤ÿ¯ÿ§ÿ³ÿ¹ÿ¸ÿÍÿÛÿÚÿÚÿÒÿáÿñ  going on....

(And wav data goes like this, i didnt paste all of it).

Yucel Bayram
  • 1,653
  • 2
  • 22
  • 41

0 Answers0