Management class @property (nonatomic, retain) Afhttprequestoperationmanager *manager; This is used to listen to the upload task, multiple requests AFN it into the thread queue @property (nonatomic, strong) afhttprequestoperation *operation; #pragma mark-Upload video
-(void) posttouploadvideo{_manager = [Afhttprequestoperationmanager manager]; _manager.responseserializer = [Afjsonresponseserializer serializer]; _manager.responseserializer.acceptablecontenttypes = [Nsset setwithobjects:@ "Application/json", @ "Text/json", @ " Text/plain ", @" text/html ", nil]; The network request needs to pass the parameters nsmutabledictionary *parameters=[[nsmutabledictionary alloc] init];
if ([Super Judgestring:app_value])
{
[Parameters Setobject:app_value Forkey:app]; } _operation = [[Afhttprequestoperation alloc]init]; Ybn_addvideo_url: Background to request URL//parameters:parameters: Network request Parameters _operation = [_manager post:ybn_addvideo_url parameters: Parameters constructingbodywithblock:^ (id<afmultipartformdata> formData)
{
if (self.videourl! = nil)
{Nserror *error;
Remove the previously added "file://" nsstring *filepath = [[Self.videourl absolutestring] stringbyreplacingoccurrencesofstring:@ " file://"withstring:@" "]; Add upload video//name:@ "Shipin": Number of parameters for network request//filename:[nsstring stringwithformat:@ "%@.mp4": The name of the video after uploading the server//mimetype:: Format of uploaded video [formData appendpartwithfileurl:[nsurl Fileurlwithpath:filepath] name:@ "Shipin" filename:[nsstring stri ngwithformat:@ "%@.mp4", [Cylfolderconfig_lib TimeStamp]] mimetype:@ "Video/mp4" error:&error];
if (Error)
{
NSLog (@ "Upload video error Reason:%@", error);
}
}
if (self.bgImage.image! = nil)
{
Add Upload image
[FormData appendpartwithfiledata:[self NarrowImageWithImage:self.bgImage.image] name:@ "Fengmian" filename:[ NSString stringwithformat:@ "%@.jpeg", [Cylfolderconfig_lib TimeStamp]] mimetype:@ "Image/jpeg"]; }
}success:^ (afhttprequestoperation *operation, id responseobject)
{NSString *rst = [NSString stringwithformat:@ "%@", [Responseobject Objectforkey:rst]]; if ([rst isequaltostring:@ "0"])
{NSLog (@ "Add video success"); }
else {NSLog (@ "Add video failed");
}
} failure:^ (Afhttprequestoperation *operation, Nserror *error) {NSLog (@ "Network request failed due to%@", error); }];} Track upload Progress [_operation setuploadprogressblock:^ (Nsuinteger byteswritten, Long long totalbyteswritten, long long Totalbytesexpectedtowrite) {NSLog (@ "Upload Progress%.2f%%", (cgfloat) totalbyteswritten/(cgfloat) totalbytesexpectedtowrite*1 00);}]; Personal understanding, not where to go please advise
Upload videos or images