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

Support custom packet size and delay in MultipartForm uploads #3228

Open
chiseller opened this issue Jun 9, 2020 · 5 comments
Open

Support custom packet size and delay in MultipartForm uploads #3228

chiseller opened this issue Jun 9, 2020 · 5 comments
Assignees

Comments

@chiseller
Copy link

In AFNetworking we can upload a file custom packet size and delay time like this
throttleBandwidthWithPacketSize:(NSUInteger)numberOfBytes delay:(NSTimeInterval)delay;
but how can i do with Alamofire?thanks!

@jshier
Copy link
Contributor

jshier commented Jun 9, 2020

There is no equivalent in Alamofire, as it does not use streams for uploads. It's unlikely we'd ever add support for this, but what's your use case?

@jshier jshier self-assigned this Jun 9, 2020
@jshier jshier added the awaiting response Issues awaits response from reporter. label Jun 9, 2020
@chiseller
Copy link
Author

chiseller commented Jun 10, 2020

hi jishier,thanks for response。Our server needs to limit the form data packet to 2kb when uploading files, and the time interval for each write is 100ms. In AFNetworking, I can set up like this:

    AFHTTPSessionManager *up = [AFHTTPSessionManager manager];
    NSString *url = "";
    [up POST:url parameters:nil headers: nil constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        [formData appendPartWithFileURL:path name:path.absoluteString error:&errors];
        //write stream 2kb each 100ms
        [formData throttleBandwidthWithPacketSize:2048 delay:0.1];
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        //do something
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        //do something
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        //do something
    }];

@jshier
Copy link
Contributor

jshier commented Jun 10, 2020

You can get the same functionality by creating your own OutputStream with the appropriate settings, which you then use with upload directly. If you need multipart encoding, you'd have to do that manually as well. Since Alamofire doesn't use streams most of the time, it's unlikely we'll add native support.

@chiseller
Copy link
Author

hey @jshier ,i find source code in MultipartFormData.swift, in BodyPart class i find InputStream,so i think that i can subclass MultipartFormData ,then custom InputStream write progress and delay time?
image

@jshier
Copy link
Contributor

jshier commented Jun 11, 2020

Good point. This needs a bit more investigation.

@jshier jshier added needs investigation and removed awaiting response Issues awaits response from reporter. labels Jun 11, 2020
@jshier jshier changed the title how can i upload a file custom packet size and delay time? Support custom packet size and delay in MultipartForm uploads Oct 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants