I'm using the otherwise excellent Alamofire to upload a file, multipart form data, as it happens to IBM Bluemix ...
Alamofire.upload(
multipartFormData: { multipartFormData in
multipartFormData.append(self.liveImageData!,
withName: "abc.jpeg", fileName: "", mimeType: "image/jpeg")
multipartFormData.append(blahFile, withName: "parameters")
},
to: theUrlString,
encodingCompletion: { encodingResult in
...
It turns out Bluemix have an incredible (and parochial) screw-up where if the header for Accept-Language is not "en" or a couple of others - it fails.
(By bad luck, Alamofire does seem to helpfully add a language header, if - say - the iPod is in Paraguay or Vietnam; or it's possible Bluemix is using some other BS like IP location.)
OK, so add a header Accept-Language:en
However, it really appears that
...there is absolutely no way in Alamofire, to both add a custom header, and upload a file?
I tried this type of thing ..
// this approach does ..... nothing
let CF = URLSessionConfiguration.default
var DH = Alamofire.SessionManager.defaultHTTPHeaders
DH["Accept-Language"] = "en"
CF.httpAdditionalHeaders = DH
superDuperManager = Alamofire.SessionManager(configuration: CF)
superDuperManager!.upload(
and it does nothing. Bummer!
Is there a way?
For anyone struggling with Bluemix, I found that the less developed but, well, better library https://github.com/JustHTTP/Just, thank goodness, resolved the issue
// use this to set a header in the oddly named "Just" library
var jds = JustSessionDefaults()
jds.headers = ["Accept-Language":"en"]
let j = JustOf<HTTP>(defaults: jds)
j.post( urlStringHere,
// data: ["name": "fattie", "pass":"321go"],
files: ["LV.jpeg": .data("LV.jpeg", liveImageData!, "image/jpeg")]
) { r in
if r.ok {
print("worked? WTH eh.")
DispatchQueue.main.async {
self.processResult(r.json)
}
}
}
Surely there's a way to set a header (when using Alamofire.upload
) in Alamo?
Note this seemingly related post https://stackoverflow.com/a/40234128/294884 simply does not work at all.