Upload videos or images

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.