0

I am uploading an image to my server, and meantime JPG image get converted, and converted image will not anymore readable.

Tried to set HTTP "Cache-Control", but no effect it has.

Any idea how to prevent conversion?

let url: NSURL = NSURL(string: "xxx")!
let request = NSMutableURLRequest(URL: url)
request.HTTPMethod = "POST"
request.setValue("private, no-store, no-cache, must-revalidate, no-transform, max-age=0", forHTTPHeaderField: "Cache-Control")
request.HTTPBody = NSData(contentsOfFile: path)

let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
NSURLSession(configuration: configuration).dataTaskWithRequest(request, completionHandler: {data, urlRequest, error in }).resume()

Attached the look of the before and after image data.

enter image description here

János
  • 27,206
  • 24
  • 130
  • 270
  • What do you mean by JPG image converted? Are you saying that the file uploaded at the server gets converted to some different format? – Utsav Dusad May 27 '16 at 12:19
  • Right, attached image about it. – János May 27 '16 at 12:36
  • no `Content-type` value in the header? poor server...! it seems you expect the server being a mind-reader or something. – holex May 27 '16 at 13:52
  • I want just save the raw data, without understanding the semantics. FYI I tried with `Content-type`: `image/jpeg` and also does not work. – János May 27 '16 at 13:55
  • I think saving the raw data is creating the problem for you. Why don't you try to upload the files using the method: `uploadTaskWithRequest: fromFile` – Utsav Dusad May 27 '16 at 13:59
  • Tried `uploadTaskWithRequest: fromFile` also, has same effect. – János May 27 '16 at 14:01
  • 1
    @János, it is not about you, it is about the server. it must know about whether the data is binary otherwise some characters might be updated by the actual system's current character encoder; in case of binary file you cannot allow that happen, which may lead you to need encoding and decoding the binary data, using like _base64_ or _ascii7_ or something as well, whichever your server-side supports and expects. – holex May 27 '16 at 14:06
  • I agree with @holex. You should check the server side code. – Utsav Dusad May 27 '16 at 14:08
  • 1
    Right problem was server side issue: http://stackoverflow.com/questions/37486019/why-node-js-convert-post-body – János May 27 '16 at 15:32

0 Answers0