ata appendPartWithFileData:data1 name:@"file" fileName:_outputPath mimeType:@"mov"];
[formData appendPartWithFileData:dataIma name:@"thumb" fileName:[NSString stringWithFormat:@"file.%@", strimageStyle] mimeType:strimageStyle];
} progress:^(NSProgress * _Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
[self stopLoading];
if ([responseObject[GetCode] intValue] == 0) {
[self.navigationController popViewControllerAnimated:YES];
}
[self showAlert:responseObject[GetMessage] type:AlertViewType_Toast];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[self stopLoading];
[self showAlert:@"上传失败请稍后重试" type:AlertViewType_Toast];
}];
+(NSString *)getImageStyle:(NSData *)data//获取图片格式
{
uint8_t c;
[data getBytes:&c length:1];
switch (c) {
case 0xFF:
return @"jpeg";
case 0x89:
return @"png";
case 0x47:
return @"gif";
case 0x49:
case 0x4D:
return @"tiff";
case 0x52:
if ([data length] < 12) {
return nil;
}
NSString *testString = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(0, 12)] encoding:NSASCIIStringEncoding];
if ([testString hasPrefix:@"RIFF"] && [testString hasSuffix:@"WEBP"]) {
return @"webp";
}
return nil;
}
return nil;
}
两种方法均可公用不在重复说明