Upload image with multipart form-data iOS in Swift

前端 未结 7 1099
無奈伤痛
無奈伤痛 2020-11-27 13:08

i am having a problem with uploading image with multipart-form

here is my code i used from this answer

    var request = NSMutableURLRequest(URL: url         


        
7条回答
  •  遥遥无期
    2020-11-27 13:58

    The first thing I noticed is the application/octet-stream as Conten-Type, this is usually used when the file type is unknown. Some web frameworks/libraries will reject this content-type if an image is required.

    Second, I can't see the post length anywhere, try to add it:

    body.appendString("--\(boundary)--\r\n")
    
    // set the content-length
    request.setValue("\(body.length)", forHTTPHeaderField:"Content-Length")
    

提交回复
热议问题