欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

iOS如何使用AFN上傳視頻到服務(wù)器

這篇文章主要介紹iOS如何使用AFN上傳視頻到服務(wù)器,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

在靖江等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站設(shè)計(jì)、做網(wǎng)站 網(wǎng)站設(shè)計(jì)制作按需定制,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站制作,成都全網(wǎng)營(yíng)銷推廣,成都外貿(mào)網(wǎng)站制作,靖江網(wǎng)站建設(shè)費(fèi)用合理。

這里介紹用AFN上傳本地拍攝的視頻到服務(wù)端。

整體思路:拿到視頻資源,先轉(zhuǎn)為mp4,寫進(jìn)沙盒,然后上傳,上傳成功后要記得刪除沙盒中的文件。

壓縮導(dǎo)出視頻

//視頻轉(zhuǎn)換為MP4
//轉(zhuǎn)碼操作...
_hud.mode = MBProgressHUDModeIndeterminate;
_hud.labelText = @"轉(zhuǎn)碼中...";
AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:_filePathURL options:nil];
NSDateFormatter* formater = [[NSDateFormatter alloc] init];
[formater setDateFormat:@"yyyyMMddHHmmss"];
_fileName = [NSString stringWithFormat:@"output-%@.mp4",[formater stringFromDate:[NSDate date]]];
_outfilePath = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/%@", _fileName];
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];

if ([compatiblePresets containsObject:AVAssetExportPresetMediumQuality]) {
  MyLog(@"outPath = %@",_outfilePath);
  AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetMediumQuality];
  exportSession.outputURL = [NSURL fileURLWithPath:_outfilePath];
  exportSession.outputFileType = AVFileTypeMPEG4;
  [exportSession exportAsynchronouslyWithCompletionHandler:^{
    if ([exportSession status] == AVAssetExportSessionStatusCompleted) {
      MyLog(@"AVAssetExportSessionStatusCompleted---轉(zhuǎn)換成功");
      _filePath = _outfilePath;
      _filePathURL = [NSURL URLWithString:[NSString stringWithFormat:@"file://%@",_outfilePath]];
       MyLog(@"轉(zhuǎn)換完成_filePath = %@\\n_filePathURL = %@",_filePath,_filePathURL);
      //獲取大小和長(zhǎng)度
      [self SetViewText];
      [self uploadNetWorkWithParam:@{@"contenttype":@"application/octet-stream",@"discription":description}];
    }else{
      MyLog(@"轉(zhuǎn)換失敗,值為:%li,可能的原因:%@",(long)[exportSession status],[[exportSession error] localizedDescription]);
      [_hud hide:YES];
      [MyHelper showAlertWith:nil txt:@"轉(zhuǎn)換失敗,請(qǐng)重試"];
    }
  }];
}

開(kāi)始上傳

- (void)uploadNetWorkWithParam:(NSDictionary*)dict {
  MyLog(@"開(kāi)始上傳_filePath = %@\\n_filePathURL = %@",_filePath,_filePathURL);
  AFHTTPRequestSerializer *ser=[[AFHTTPRequestSerializer alloc]init];
  NSMutableURLRequest *request =
  [ser multipartFormRequestWithMethod:@"POST"
               URLString:[NSString stringWithFormat:@"%@%@",kBaseUrl,kVideoUploadUrl]
               parameters:@{@"path":@"show",@"key":_key,@"discription":dict[@"discription"],@"isimage":@(_isImage)}
       constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
           [formData appendPartWithFileURL:_filePathURL name:@"file" fileName:_fileName mimeType:dict[@"contenttype"] error:nil];
         if (!_isImage) {
    [formData appendPartWithFileURL:_path3Url name:@"tmp" fileName:@"tmp.PNG" mimeType:@"image/png" error:nil];
         }
       } error:nil];
  //@"image/png"  @"application/octet-stream" mimeType
  AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
  NSProgress *progress = nil;
  NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
    if (error) {
       MyLog(@"request = %@", request );
       MyLog(@"response = %@", response );
      MyLog(@"Error: %@", error );
      [_hud hide:YES];
      CXAlertView *alert=[[CXAlertView alloc]initWithTitle:NSLocalizedString(@"Warning", nil)
                             message:NSLocalizedString(@"Upload Failed",nil)
                        cancelButtonTitle:NSLocalizedString(@"Iknow", nil)];
      alert.showBlurBackground = NO;
      [alert show];
    } else {
      MyLog(@"%@ %@", response, responseObject);
      NSDictionary *backDict=(NSDictionary *)responseObject;
      if ([backDict[@"success"] boolValue] != NO) {
        _hud.labelText = NSLocalizedString(@"Updating", nil);
        [self UpdateResxDateWithDict:backDict discription:dict[@"discription"]];
        [_hud hide:YES];
      }else{
        [_hud hide:YES];
        [MyHelper showAlertWith:nil txt:backDict[@"msg"]];
      }
    }
    [progress removeObserver:self
           forKeyPath:@"fractionCompleted"
             context:NULL];
  }];
  [progress addObserver:self
        forKeyPath:@"fractionCompleted"
         options:NSKeyValueObservingOptionNew
         context:NULL];
  [progress setUserInfoObject:@"someThing" forKey:@"Y.X."];
  [uploadTask resume];
}

清除documents中視頻

-(void)ClearMovieFromDoucments{
  NSFileManager *fileManager = [NSFileManager defaultManager];
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  NSString *documentsDirectory = [paths objectAtIndex:0];
  NSArray *contents = [fileManager contentsOfDirectoryAtPath:documentsDirectory error:NULL];
  NSEnumerator *e = [contents objectEnumerator];
  NSString *filename;
  while ((filename = [e nextObject])) {
    MyLog(@"%@",filename);
    if ([filename isEqualToString:@"tmp.PNG"]) {
      MyLog(@"刪除%@",filename);
      [fileManager removeItemAtPath:[documentsDirectory stringByAppendingPathComponent:filename] error:NULL];
      continue;
    }
    if ([[[filename pathExtension] lowercaseString] isEqualToString:@"mp4"]||
      [[[filename pathExtension] lowercaseString] isEqualToString:@"mov"]||
      [[[filename pathExtension] lowercaseString] isEqualToString:@"png"]) {
      MyLog(@"刪除%@",filename);
      [fileManager removeItemAtPath:[documentsDirectory stringByAppendingPathComponent:filename] error:NULL];
    }
  }
}

以上是“iOS如何使用AFN上傳視頻到服務(wù)器”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

本文名稱:iOS如何使用AFN上傳視頻到服務(wù)器
URL網(wǎng)址:http://aaarwkj.com/article22/gjihcc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、定制網(wǎng)站、網(wǎng)站排名、靜態(tài)網(wǎng)站ChatGPT、移動(dòng)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)
欧美黄片免费在线视频| 欧美精品一区二区精品久久| 中文字幕一区二区精品区| 日韩少妇人妻一区二区| 婷婷色综合一区二区三区| 女人裸体网站无遮挡午夜| 麻豆精品情欲人妻一区| 国产亚洲一区二区三区成人| 欧美国产大片一区视频| 国产,欧美,日韩,日日骚| 国产精品剧情在线播放| 成人午夜激情四射av| 国产精品久久久久久老熟女| 亚洲毛片在线免费播放| 日韩欧美午夜福利在线视频| 日本一区二区久久人妻高清| 亚洲人的av在线播放| 精品人妻一区二区三区久久91| 亚洲成在人天堂一区二区| 在线观看不卡的黄色地址| 三级日本午夜在线观看| 粉嫩一区二区三区在线| 91在线观看高清免费| 国外男女性生活在线视频| 清纯美女爱爱高潮av| 日韩av有码在线播放| 精品人妻一区二区在线99| 免费一区二区三区精品| 最新日韩中文字幕在线播放| 熟女中文字幕一区二区| 亚洲欧美日韩综合一区| 巴西老熟女大奶子多毛逼| 亚洲日本高清一二三区| 成年人三级黄色片视频| 萌白的所有视频在线观看| 国产三级精品三级专区| 日韩中文字幕 在线播放| 国产极品美女在线观看网站| 在线不卡日本v二区到六区| 在线国产一区二区不卡| 国产成人综合亚洲欧美在线|