Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uploading streams #146

Closed
ecoopnet opened this issue Mar 23, 2016 · 3 comments
Closed

Uploading streams #146

ecoopnet opened this issue Mar 23, 2016 · 3 comments
Milestone

Comments

@ecoopnet
Copy link

I want to upload stream without creating NSData (like Alamofire/AFNetworking)
because uploading very large file(like long movie file) will cause crash by memory problem.

I tried to create custom RequestBodyBuilder but buildBodyFromObject return NSData...
Please tell me how to fix this problem on APIKit 1 or 2?

@ecoopnet ecoopnet changed the title Support uploading streams Uploading streams Mar 23, 2016
@ishkawa
Copy link
Owner

ishkawa commented Mar 23, 2016

APIKit 2 supports both NSData and NSInputStream, but APIKit 1 supports NSData only.

On APIKit 2, RequestBodyBuilder enumeration is converted to BodyParametersType protocol, which returns RequestBodyEntity. Since RequestBodyEntity can represents NSInputStream, your custom body parameters can return NSInputStream.

public enum RequestBodyEntity {
    case Data(NSData)
    case InputStream(NSInputStream)
}

public protocol BodyParametersType {
    var contentType: String { get }
    func buildEntity() throws -> RequestBodyEntity
}

By the way, I will adopt NSInputStream in MultipartFormDataParameters in the future beta of APIKit 2.

@ishkawa ishkawa added this to the 2.0 milestone Mar 23, 2016
@ecoopnet
Copy link
Author

Thats great!

I am just using multipart form data on APIKit 1.
So I'll try APIKit2 next time.

Thanks for your nice answer.

@ishkawa
Copy link
Owner

ishkawa commented May 7, 2016

NSStream-based MultipartFormDataParameters is implemented in #160 and available in 2.0.0 beta 4!

@ishkawa ishkawa closed this as completed May 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants