Is imageArray definitely an array of URL's? Somewhere, someone's expecting a string, but they're getting an image. Based on:lastPathComponent
(a NSString method) being called on a UIImage.
Uploading an array of images using AFNetworking 2 Batch requests
-
11-07-2023 - |
Vra
I have an array of images that I'm trying to upload to a server using AFNetworking batch request. Here is my code, I'm getting an error and I'm not sure why
-(void)imageUploader {
NSArray *imageArray = _listing.productImageArray;
imageCounter = 1;
NSString * ts = [NSString stringWithFormat:@"%f",[[NSDate new] timeIntervalSince1970] * 1000];
NSMutableArray *mutableOperations = [NSMutableArray array];
for (NSURL *fileURL in imageArray) {
imagesUploaded = 0;
NSString *counter = [NSString stringWithFormat:@"%i", imageCounter];
NSURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:@"https://myayla.com/bl/saveProductImages.php" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileURL:fileURL name:@"images[]" error:nil];
} error:nil];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[mutableOperations addObject:operation];
}
NSArray *operations = [AFURLConnectionOperation batchOfRequestOperations:mutableOperations progressBlock:^(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations) {
NSLog(@"%lu of %lu complete", numberOfFinishedOperations, totalNumberOfOperations);
} completionBlock:^(NSArray *operations) {
NSLog(@"All operations in batch complete");
}];
[[NSOperationQueue mainQueue] addOperations:operations waitUntilFinished:NO];
here is the error
'NSInvalidArgumentException', reason: '-[UIImage lastPathComponent]: unrecognized selector sent to instance
Can anyone help out? Thanks
Oplossing
Gelisensieer onder: CC-BY-SA met toeskrywing
Nie verbonde aan StackOverflow