//獲取簽名?
?[[QLMNetworkTools sharedTools] requestWithType:GET andUrlStr:[NSString stringWithFormat:@"%@%@",Test_Net_URL,Voide_getSign_Port] andParams:nil andSuccess:^(id responseObject) {
?if ([responseObject[@"status"] integerValue] == 200) {?
? ? ? ? ?QNConfiguration *config = [QNConfiguration build:^(QNConfigurationBuilder *builder) {
? ? ? ? ?builder.useHttps = YES;
? ? ? ?}];?
?QNUploadManager *upManager = [[QNUploadManager alloc]initWithConfiguration:config];
?//將音樂上傳到七牛?
?[upManager putFile:musicPath key:musicPath token:responseObject[@"data"][@"upToken"] ?complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
? ? ? if(info.ok) {?
? ? AFHTTPSessionManager * session=[[AFHTTPSessionManager alloc]init]; session.requestSerializer=[AFHTTPRequestSerializer serializer];?
?session.responseSerializer=[AFHTTPResponseSerializer serializer]; [session POST:[NSString stringWithFormat:@"%@%@",Test_Net_URL,Upload_music_port] parameters:paramters constructingBodyWithBlock:^(id _Nonnull formData) {
? ? ? ? ? ? ? ? ? ? ? ? NSData *musicData = [NSData dataWithContentsOfFile:musicPath];
? ? ? ? ? ? ? ? ? ? ? ? NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
? ? ? ? ? ? ? ? ? ? ? ? formatter.dateFormat = @"yyyyMMddHHmmss";
? ? ? ? ? ? ? ? ? ? ? ? NSString *str = [formatter stringFromDate:[NSDate date]];
? ? ? ? ? ? ? ? ? ? ? ? NSString *fileName = [NSString stringWithFormat:@"%@.mp3", str];
? ? ? ? ? ? ? ? ? ? ? ? //上傳的參數(shù)(以文件流的格式)
? ? ? ? ? ? ? ? ? ? ? ? [formData appendPartWithFileData:musicData
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? name:@"file"
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? fileName:fileName
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? mimeType:@"application/octer-stream"];
? ? ? ? ? ? ? ? ? ? } progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id? _Nullable responseObject) {
? ? ? ? ? ? ? ? ? ? ? ? id json = [NSJSONSerialization JSONObjectWithData: responseObject options:0 error:nil];
? ? ? ? ? ? ? ? ? ? ? ? [SVProgressHUD dismiss];
? ? ? ? ? ? ? ? ? ? ? ? if ([json[@"status"] integerValue] == 200) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? NSLog(@"上傳音樂成功 -- %@",json)
?? ? ? ? ? ? ? ? ? ? ? ?}else{
?? ? ? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ? } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
? ? ? ? ? ? ? ? ? ? ? ? NSLog(@"%@",error);
? ? ? ? ? ? ? ? ? ? ? ? [SVProgressHUD dismiss];
? ? ? ? ? ? ? ? ? ? }];
? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? NSLog(@"失敗");
?? ? ? ? ? ? ? ? ? ?//如果失敗,這里可以把info信息上報自己的服務器,便于后面分析上傳錯誤原因
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? NSLog(@"info ===== %@", info);
? ? ? ? ? ? ? ? NSLog(@"resp ===== %@", resp);
? ? ? ? ? ? } option:nil];
? ? ? ? }else{
? ? ? ? }
? } andFailture:^(NSError *error) {
??NSLog(@"%@",error);
? ? }];