I'm trying to upload an image to a cloud storage with NSURLSession.
let data = UIImageJPEGRepresentation(imageAttachment, 1)
NSURLSession.sharedSession().uploadTaskWithRequest(request, fromData: data)
The image has been successfully uploaded, but it seems that the server does not recognize the data as an image. When I checked the content type from the cloud storage's console, it is set as application/octet-stream
.
My question: how to specify mime type for file uploaded with NSURLSession?
Never mind, I got it.
I need to set the
Content-type
header withNSMutableURLRequest
before passing it in touploadTaskWithRequest
.