alamofire

How can we upload multipart form data with nested JSON parameters in Swift?

别来无恙 提交于 2019-12-21 06:27:13
问题 I need to upload an image to the server endpoint where the structure has to be as following: { "image": { "file": imageData }, "access_token": access_token } How can I send such a request using NSURLSession (or maybe even Alamofire or AFNetworking)? 回答1: You cannot just include binary image data in a JSON request. JSON requires text representation, so if you do this, you must convert it to string (e.g. base64 encoding), use that in the JSON, and then the server code would presumably convert

The file “xxx.mp4” couldn’t be opened because you don’t have permission to view it

守給你的承諾、 提交于 2019-12-21 04:53:21
问题 I use the Alamofire method multipartFormData.append(URL, withName: "file") to upload a video to the server but I've got an error message: multipartEncodingFailed(Alamofire.AFError.MultipartEncodingFailureReason.bodyPartFileNotReachableWithError(file:///var/mobile/Media/DCIM/100APPLE/IMG_0939.mp4, Error Domain=NSCocoaErrorDomain Code=257 " The file “IMG_0939.mp4” couldn’t be opened because you don’t have permission to view it. " UserInfo={NSURL=file:///var/mobile/Media/DCIM/100APPLE/IMG_0939

Setting Custom HTTP Headers in Alamofire in iOS 7 not working

删除回忆录丶 提交于 2019-12-21 03:43:24
问题 I've tried to set the Alamofire.Manager.sharedInstance.session.configuration.HTTPAdditionalHeaders with my custom HTTP Headers in iOS 7 but I have had no luck. This works fine in iOS 8. Does anyone have any suggestions? 回答1: I got it working. This has no effect on iOS7: Alamofire.Manager.sharedInstance.session.configuration.HTTPAdditionalHeaders = ["CustomHeader": customValue] This however will work on both iOS7 & 8: var headers = Alamofire.Manager.sharedInstance.session.configuration

Alamofire request with cookies

假如想象 提交于 2019-12-20 14:47:33
问题 I'm beginner and I can't figure out how to make a .GET request (however it requires autenthication) with Alamofire. I managed to do this with other web service (login) because it takes parameters argument: parameters = [ "username" : username "password" : password ] Then: Alamofire.request(.POST, loginUrl, parameters: parameters).responseJSON { (request, response, data, error) -> Void in //handling the response } In response header I get some information: [Transfer-Encoding: Identity, Server:

Alamofire request with cookies

最后都变了- 提交于 2019-12-20 14:46:03
问题 I'm beginner and I can't figure out how to make a .GET request (however it requires autenthication) with Alamofire. I managed to do this with other web service (login) because it takes parameters argument: parameters = [ "username" : username "password" : password ] Then: Alamofire.request(.POST, loginUrl, parameters: parameters).responseJSON { (request, response, data, error) -> Void in //handling the response } In response header I get some information: [Transfer-Encoding: Identity, Server:

Alamofire not working (Swift/Xcode 8)

烈酒焚心 提交于 2019-12-20 10:32:38
问题 I am getting the following errors when trying to import Alamofire into my project (Cocoapods isn't working for me, so I have to manually import it). Anyway, I'm using XCode 8 and Swift 2.3, and I'm getting these errors: Update: I cleaned XCode, downloaded the latest version of Alamofire and restarted my computer. Now, XCode seems to be giving me conflicting errors (pictures for reference) Thanks! 回答1: As of early September '16, you need to use the following in your Podfile: pod 'Alamofire',

Does Alamofire store the cookies automatically?

吃可爱长大的小学妹 提交于 2019-12-20 09:16:34
问题 I'm new to Alamofire so I'm sorry if this it's a noob question: this framework stores the cookies automatically ? This is because I have a simple request like this: Alamofire.request(.POST, loginURL, parameters: ["fb_id": fbId, "fb_access_token": fbToken]) .responseJSON { response in //print(response.request) // original URL request //print(response.response) // URL response //print(response.data) // server data //print(response.result) // result of response serialization if let JSON =

Alamofire multipart upload post error in Swift

☆樱花仙子☆ 提交于 2019-12-20 07:37:26
问题 When i tried to upload image using Alamofire I'm getting error in .POST Im attaching an image along with this to show the error (http://www.awesomescreenshot.com/image/422237/0d5fe4a4b486b14fdf52f8ca26d22bea) 回答1: I had the same problem , as Michal said it's an installation issue if you are using cocoapods go to your project files/pods/Alamofires/Source and make sure you have 9 files there just like this image and make sure that the MultipartFormData.swift file is there if you are not using

Alamofire multipart upload post error in Swift

£可爱£侵袭症+ 提交于 2019-12-20 07:37:16
问题 When i tried to upload image using Alamofire I'm getting error in .POST Im attaching an image along with this to show the error (http://www.awesomescreenshot.com/image/422237/0d5fe4a4b486b14fdf52f8ca26d22bea) 回答1: I had the same problem , as Michal said it's an installation issue if you are using cocoapods go to your project files/pods/Alamofires/Source and make sure you have 9 files there just like this image and make sure that the MultipartFormData.swift file is there if you are not using

Postman request to Alamofire request

杀马特。学长 韩版系。学妹 提交于 2019-12-20 07:35:53
问题 I'm having no issues when I make the post request with POSTMAN but when I use alamofire I have issues. The post still goes through on the alamofire request but the data is not received the same way. What does an alamofire request look like that's the exact same as the following postman... 回答1: Swift 2.x : typealias apiSuccess = (result: NSDictionary?) -> Void typealias apiProgress = (result: NSDictionary?) -> Void // when you want to download or upload using Alamofire.. typealias apiFailure =