AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager.requestSerializer setValue:@"multipart/form-data" forHTTPHeaderField:@"Content-Type"];
NSString *urlString =UpLoadUrl;
// //post請求
[manager POST:urlString parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyyMMddHHmmss";
NSString *str = [formatter stringFromDate:[NSDate date]];
NSString *fileName = [NSString stringWithFormat:@"%@.mp4", str];
/*
此方法參數(shù)
1. 要上傳的[二進制數(shù)據(jù)]
2. 我這里的imgFile是對應后臺給你url里面的圖片參數(shù)七蜘,別瞎帶墙懂。
3. 要保存在服務器上的[文件名]
4. 上傳文件的[mimeType]
*/
NSURL * videoUrl = [NSURL URLWithString:path];
// NSLog(@"視頻地址是====%@",videoUrl);
[formData appendPartWithFileURL:videoUrl name:@"mfile" fileName:fileName mimeType:@"video/mpeg4" error:(nil)];
} progress:^(NSProgress * _Nonnull uploadProgress) {
float progress = 1.0 * uploadProgress.completedUnitCount/uploadProgress.totalUnitCount;
// NSLog(@"上傳視頻進度%f",progress);
//找到message大數(shù)組中對應數(shù)據(jù)以更改橡卤,加入上傳進度
NSString *who;
int which = 0;
NSString *file1 = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:@"message.count"];
if (![[NSFileManager defaultManager] fileExistsAtPath:file1]) {
}else{
NSMutableDictionary *countDic = [[NSMutableDictionary alloc]initWithContentsOfFile:file1];
NSString* time = [NSString stringWithFormat:@"%ld",timeStamp];
NSMutableDictionary *valueDic = [countDic objectForKey: time];
who = [valueDic objectForKey:@"to"];
which = [[valueDic objectForKey:@"count"] intValue];
NSData *userData = [[NSUserDefaults standardUserDefaults] objectForKey:K_USER_USERMESSAGE];
MxmUserMessage *mxmUserModel = [NSKeyedUnarchiver unarchiveObjectWithData:userData];
NSString *my = mxmUserModel.userName;
NSString *file = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:@"message.data"];
if (![[NSFileManager defaultManager] fileExistsAtPath:file]) {
}else{
NSMutableDictionary *aDic = [[NSMutableDictionary alloc]initWithContentsOfFile:file];
NSMutableArray *dataArr = [aDic objectForKey:my];
for (int i = 0; i<dataArr.count; i++) {
NSMutableArray *smallArr = [dataArr objectAtIndex:i];
//下面三句只是為了拿到samllArr中每個字的key(每個字典的key都是相同的)
NSMutableDictionary *msgDic = [smallArr objectAtIndex:0];
NSArray *keyArr = msgDic.allKeys;
NSString *key = keyArr[0];
if ([key isEqualToString:who]) {
NSMutableDictionary *msgDic1 = [smallArr objectAtIndex:which -1];
NSMutableDictionary *keyDic = [msgDic1 objectForKey:key];
[keyDic setObject:@"1" forKey:@"isSender"];
[keyDic setObject:[NSString stringWithFormat:@"%f",progress] forKey:@"uploadProgress"];
[msgDic1 setObject:keyDic forKey:key];
[smallArr replaceObjectAtIndex:which -1 withObject:msgDic1];
[dataArr replaceObjectAtIndex:i withObject:smallArr];
[aDic setObject:dataArr forKey:my];
[aDic writeToFile:file atomically:YES];
// NSLog(@"加入了上傳進度-- 第%d句,時間是%@",which,time);
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter]postNotificationName:@"loadDataSource" object:nil];
});
}
}
}
}
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSString *mediaID = [responseObject objectForKey:@"mediaid"];
NSString* urlStr= [NSString stringWithFormat:@"%@/%@",DownLoadUrl,mediaID];
if (your.length <36) {
[vc sendMessageWithContent:urlStr localUrl:path type:type realTime:timeStamp];
}else{
JFGroupChatController *groupVC = [[JFGroupChatController alloc]init];
[groupVC sendMessageWithContent:urlStr localUrl:path type:type realTime:timeStamp];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"請求失敗:%@",error);
}];
AFN上傳視頻
最后編輯于 :
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來菠劝,“玉大人,你說我怎么就攤上這事赶诊。” “怎么了舔痪?”我有些...
- 文/不壞的土叔 我叫張陵锌唾,是天一觀的道長。 經(jīng)常有香客問我晌涕,道長,這世上最難降的妖魔是什么渐排? 我笑而不...
- 正文 為了忘掉前任驯耻,我火速辦了婚禮炒考,結果婚禮上,老公的妹妹穿的比我還像新娘斋枢。我一直安慰自己,他們只是感情好瓤帚,可當我...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著轩勘,像睡著了一般匪傍。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
- 文/蒼蘭香墨 我猛地睜開眼工碾,長吁一口氣:“原來是場噩夢啊……” “哼百姓!你這毒婦竟也來了?” 一聲冷哼從身側響起垒拢,我...
- 正文 年R本政府宣布辞居,位于F島的核電站蛋勺,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏抱完。R本人自食惡果不足惜,卻給世界環(huán)境...
- 文/蒙蒙 一巧娱、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧禁添,春花似錦、人聲如沸老翘。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至傀履,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間啤呼,已是汗流浹背。 一陣腳步聲響...
推薦閱讀更多精彩內(nèi)容
- 用實現(xiàn)的功能: 利用UIImagePickerController拍攝視頻撩荣、圖片,并從圖庫中選擇圖片或者視頻上傳 ...
- 1.獲取視頻路徑 2.創(chuàng)建壓縮視頻類.h文件 import <Foundation/Foundation.h> i...
- 我們在項目中有時會碰到視頻相關的需求,一般的可以分為幾種情況: 1. 簡單的視頻開發(fā)敌厘,對界面無要求,可直接使用系統(tǒng)...
- 1.物理錯題 2.物理反思 3.默《師說》尚骄、《赤壁賦》 4.化學白本專題 5.化學卷子兩份 6.生物世紀金榜2.1...