0

I need to send a multipart/form-data HTTP POST request with a file and some extra data. The files might be kind of big, so I cannot read them with NSData because it will trigger a memory issue, so the file has to be read with NSInputStream.

I've been doing some research and found a solution for Objective-C: https://github.com/pyke369/PKMultipartInputStream

Is there something similar for Swift?

Olav Gausaker
  • 496
  • 3
  • 14
  • Have a look at this article, towards the end https://medium.com/swift-programming/learn-nsurlsession-using-swift-part-3-upload-3a5be9a69950 "Handle Stream Upload" – sbarow Jul 23 '15 at 14:33
  • I read the article before, thanks. The problem is that I need to implement my own NSInputStream that can handle (NSData) + (the contents of a file) on a single stream. Basically, append both, but the file cannot be loaded as NSData because it will run out of memory. – Olav Gausaker Jul 23 '15 at 14:39

1 Answers1

0

I wrote my custom NSInputStream subclass for uploading ALAseets. POSInputStreamLibrary has flexible enough architecture to reuse it for writing any streams you want. At least you can look at its sources to get an idea. The library is written with Objective-C, but I don't see any problem to use/rewrite it in Swift.

Pavel Osipov
  • 2,067
  • 1
  • 19
  • 27
  • Thanks. I'll try to use the PKMultipartInputStream class I found from Swift which suits my needs. I'll posts the results. – Olav Gausaker Jul 24 '15 at 12:34