gpt4 book ai didi

ios - AFnetworking 取消特定上传过程

转载 作者:行者123 更新时间:2023-11-29 02:16:09 25 4
gpt4 key购买 nike

我正在服务器上上传多个图像,所有图像的 URL 都是相同的。以下是代码。

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.securityPolicy.allowInvalidCertificates = YES;

manager.requestSerializer = [AFHTTPRequestSerializer serializer];
manager.responseSerializer = [AFJSONResponseSerializer serializer];

NSDictionary *parameters = @{KEY: VALUE};
NSString *imageUrl=[NSString stringWithFormat:@"%@/user/upload/item",BASE_SERVER_ADDRESS];


AFHTTPRequestOperation *op = [manager POST:imageUrl parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {

NSString *imageName = [NSString stringWithFormat:@"IMG00%i.png",count];

[formData appendPartWithFileData:_imageData name:@"files" fileName:imageName mimeType:@"image/png"];

} success:^(AFHTTPRequestOperation *operation, id responseObject) {

NSLog(@"Success: %@ ***** %@", operation.responseString, responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@ ***** %@", operation.responseString, error);
}];
[op setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
double percentDone = (double)totalBytesWritten / (double)totalBytesExpectedToWrite;
//Upload Progress bar here
NSLog(@"progress updated(percentDone) : %f", percentDone);

}];
[op start];

我并行上传 10 张图像并获取每个图像单独的进度。现在我想取消特定的上传图像,例如第五张图像。我怎样才能获得该图像的操作。operationQueue 里面只有 NSOperation 。我如何知道特定的 NSOperation 是我想要取消的操作。谢谢。

最佳答案

您需要将需要取消的操作存储在一个变量中,稍后调用[op cancel]

关于ios - AFnetworking 取消特定上传过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28726866/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com