ios - How to upload a live photo to the server? -
how upload live photos server? using afnetworking upload of images, videos, , slow motion videos. upload of images , videos straightforward.
upload of images , videos
//physical location i.e. url video phvideorequestoptions *options = [phvideorequestoptions new]; options.networkaccessallowed = yes; [[phimagemanager defaultmanager] requestavassetforvideo:asset options:options resulthandler:^(avasset *asset, avaudiomix *audiomix, nsdictionary *info) { if ([asset iskindofclass:[avurlasset class]]) { nslog(@"%@",((avurlasset *)asset).url); } }]; //physical location i.e. url image [asset requestcontenteditinginputwithoptions:nil completionhandler:^(phcontenteditinginput *contenteditinginput, nsdictionary *info) { nsurl *imageurl = contenteditinginput.fullsizeimageurl; }];
these urls used upload of images , video files.
// manager of class afhttpsessionmanager initialised background session. nsurlsession *uploadtask=[manager uploadtaskwithrequest:request fromfile:[nsurl urlwithstring:fdi.filepath] progress:nil completionhandler:nil];
upload of slow motion file
slow motion file combination of 2 or more video files. if try upload normal video file loose slow motion feature. work out, first have create slow motion file, save on disk , upload it.
phvideorequestoptions *options = [phvideorequestoptions new]; options.networkaccessallowed = yes; [[phimagemanager defaultmanager] requestavassetforvideo:asset options:options resulthandler:^(avasset *asset, avaudiomix *audiomix, nsdictionary *info) { if(([asset iskindofclass:[avcomposition class]] && ((avcomposition *)asset).tracks.count == 2)){ //added ud slow motion videos. see here: https://overflow.buffer.com/2016/02/29/slow-motion-video-ios/ //output url nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdirectory = paths.firstobject; nsstring *mypathdocs = [documentsdirectory stringbyappendingpathcomponent:[nsstring stringwithformat:@"mergeslowmovideo-%d.mov",arc4random() % 1000]]; nsurl *url = [nsurl fileurlwithpath:mypathdocs]; //begin slow mo video export avassetexportsession *exporter = [[avassetexportsession alloc] initwithasset:asset presetname:avassetexportpresethighestquality]; exporter.outputurl = url; exporter.outputfiletype = avfiletypequicktimemovie; exporter.shouldoptimizefornetworkuse = yes; [exporter exportasynchronouslywithcompletionhandler:^{ dispatch_async(dispatch_get_main_queue(), ^{ if (exporter.status == avassetexportsessionstatuscompleted) { nsurl *url = exporter.outputurl; self.filepath=url.absolutestring; nsurlsession *uploadtask=[manager uploadtaskwithrequest:request fromfile:[nsurl urlwithstring:self.filepath] progress:nil completionhandler:nil]; //use above method or use below one. // nsdata *videodata = [nsdata datawithcontentsofurl:url]; // //// upload //[self uploadselectedvideo:video data:videodata]; } }); }]; } }];
how upload live photo?
a live photo combination of 2 files, *.jpg , *mov. can neither upload photo or video nor can create new file combination of 2 or more files did slow motion video because have send both files of live photo server.
it clear have send both files server. how send multiple files in single request.
read interesting solution problem. suggests not need upload both *jpg , *.mov server live photo. can upload video , create image @ server mid point of video.
the live photo begins middle of video - read video, find middle, save image.
we can create live photo video iphone 6s does. 6s captures short video photo , plays video when photo 3d touched. however, using method of creating phlivephoto , playing using phlivephotoview, can work on iphone, such regular iphone 6.
source: see here.
we can video url of live photo. see how extract video url live photo.
but not sure whether solution problem. can tell me whether solution or not.
Comments
Post a Comment