I know this question has been asked before but I can't figure out the correct way from those posts. So here is my code to upload a video file that causes memory issues:
AFHTTPSessionManager *operationManager = [AFHTTPSessionManager manager];
operationManager.responseSerializer=[AFJSONResponseSerializer serializer];
operationManager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
//[operationManager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[operationManager.operationQueue cancelAllOperations];
if([requestName isEqualToString:addComment_Url] && [dict valueForKey:@"image_Data"] != nil && [dict valueForKey:@"mime_type"] != nil){
}
[operationManager.requestSerializer setValue:authValue forHTTPHeaderField:@"Authorization"];
[operationManager POST:url parameters:dict constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
SAAppDelegate *appDelegate = [SAAppDelegate getDelegate];
if([requestName isEqualToString:addComment_Url] && appDelegate.imageData !=nil){
// [formData appendPartWithFormData:self.imageData name:@"myFile"];
[formData appendPartWithFileData:appDelegate.imageData name:@"myFile" fileName:appDelegate.fileName mimeType:appDelegate.mime];
}
if([requestName isEqualToString:addNewPost_Url] && appDelegate.imageData !=nil){
[formData appendPartWithFileData:appDelegate.imageData name:@"myFile" fileName:appDelegate.fileName mimeType:appDelegate.mime];
}
if([requestName isEqualToString:send_message_Url] && appDelegate.imageData !=nil){
[formData appendPartWithFileData:appDelegate.imageData name:@"myFile" fileName:appDelegate.fileName mimeType:appDelegate.mime];
}
} progress:^(NSProgress * _Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
arrayParsedJson = (NSMutableArray * )responseObject;
[self.delegate dataReceivedFromService:arrayParsedJson withRequestName:requestName];
//
//[hud hideAnimated:YES];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
}];
Can anyone explain me what's wrong here?
In my opinion, you should use method
Input is URLString, not NSData. AFNetworking can handle data issue for you. This is my experience after my application crashed when upload too large video. Hope this helpful.
My project code for your reference
Try this With image parameter and video parameter, If you want to pass only video parameter then make image parameter as nil and same for image parameter
for using this