// // UploadImgVo.m // // // Created by cs on 15/8/24. // Copyright (c) 2015年. All rights reserved. // #import "UploadImgVo.h" #import "AFNetSessionClient.h" #import "AppDelegate.h" #import "LoginMainViewController.h" @implementation UploadImgVo +(NSURLSessionDataTask *)uploadImg:(NSString *)strPath withDic:(NSDictionary *)parameters withSuccess:(AFNetSessionSuccessModelBlock)success withFialure:(AFNetSessionFailBlock)failure{ [[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:YES]; AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; NSString *strToken; NSString *strUserId; if (appDelegate.loginMainViewController.isLogin) { strToken = appDelegate.loginMainViewController.user.token; strUserId = [NSString stringWithFormat:@"%d",appDelegate.loginMainViewController.user.mid]; }else{ strToken = DefaultToken; strUserId = @"0"; } [parameters setValue:strToken forKey:@"token"];//artist/uploadImg return [[AFNetSessionClient sharedClient] POST:[NSString stringWithFormat:@"user/%@/%@",strUserId,strPath] parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { [[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:NO]; UIImage *image = [parameters valueForKey:@"image"]; NSData *imageData = UIImageJPEGRepresentation(image, 0.5); // NSData *imageData = UIImagePNGRepresentation(image); NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; formatter.dateFormat = @"yyyyMMddHHmmss"; NSString *str = [formatter stringFromDate:[NSDate date]]; NSString *fileName = [NSString stringWithFormat:@"%@.jpg", str]; // NSString *fileName = [NSString stringWithFormat:@"%@.png", str]; [formData appendPartWithFileData:imageData name:@"imgFile" fileName:fileName mimeType:@"image/jpg"]; } success:^(NSURLSessionDataTask *task, id responseObject) { DLOG(@"图片上传成功"); NSError *error; NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:&error]; if (success) { if (!error.code == 0) { failure(error,nil,nil); }else{ NSString *status =[dic valueForKey:@"status"]; if ([status isEqualToString:@"200" ]) { success(dic); } else { NSString *message = [dic valueForKey:@"message"]; failure(nil,status,message); } } } } failure:^(NSURLSessionDataTask *task, NSError *error) { DLOG(@"上传图片异常::%@",error.description); [[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:NO]; if (failure) { failure(error,nil,nil); } }]; } +(NSURLSessionDataTask *)uploadMp3:(NSString *)strPath withDic:(NSDictionary *)parameters withSuccess:(AFNetSessionSuccessModelBlock)success withFialure:(AFNetSessionFailBlock)failure{ [[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:YES]; AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; NSString *strToken; NSString *strUserId; if (appDelegate.loginMainViewController.isLogin) { strToken = appDelegate.loginMainViewController.user.token; strUserId = [NSString stringWithFormat:@"%d",appDelegate.loginMainViewController.user.mid]; }else{ strToken = DefaultToken; strUserId = @"0"; } [parameters setValue:strToken forKey:@"token"]; return [[AFNetSessionClient sharedClient] POST:[NSString stringWithFormat:@"user/%@/%@",strUserId,strPath] parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { [[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:NO]; NSString *mp3Path = [parameters valueForKey:@"mp3"]; NSData* mp3Data= [NSData dataWithContentsOfFile:mp3Path]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; formatter.dateFormat = @"yyyyMMddHHmmss"; NSString *str = [formatter stringFromDate:[NSDate date]]; NSString *fileName = [str stringByAppendingPathExtension:@"mp3"]; [formData appendPartWithFileData:mp3Data name:@"imgFile" fileName:fileName mimeType:@"audio/mp3"]; } success:^(NSURLSessionDataTask *task, id responseObject) { DLOG(@"文件上传成功"); NSError *error; NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:&error]; if (success) { if (!error.code == 0) { failure(error,nil,nil); }else{ NSString *status =[dic valueForKey:@"status"]; if ([status isEqualToString:@"200" ]) { success(dic); } else { NSString *message = [dic valueForKey:@"message"]; failure(nil,status,message); } } } } failure:^(NSURLSessionDataTask *task, NSError *error) { DLOG(@"上传图片异常::%@",error.description); [[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:NO]; if (failure) { failure(error,nil,nil); } }]; } @end
相关推荐
zphupload.js 文件上传拖拽效果,以及图片,MP3,MP4格式的预览,ajax上传
Layui图片上、视频、音频、文件上传接口及跨域上传,此项目案例包含了多种上传方式,欢迎大家下载
此文件是对微信小程序,上传图片或者录音文件到阿里云oss代码的封装个, 1上传图片引用示例 wx.chooseImage({ count: 3, // 默认最多一次选择9张图 sizeType: ['original', 'compressed'], // 可以指定是原图还是...
MP3数据的传输是gzip压缩的,服务器端存了压缩和不压缩的版本。 这个flash还带播放功能,能播放压缩和没有压缩过的mp3。 使用方法见rec.php;支持ie,ff,chrome,safari。 只要5分,超值,其它的都要10分!!
使用的是jquery的xheditor+struts实现了想QQ...在文本编辑框了您可以插入图片!电影!压缩包等多种文件!且页面及后台都有详细的注释!通俗易懂!同时使用了jquery-uploadify的插件+struts实现的带进度条的大文件上传
包括但不限于文章、文档、音频、视频、图片、课程、软件、源代码等相关资源
php图片音频上传源码附带,可以上传jpg、png、jpeg、mp3、MP4等多种格式本人测试有效
图酷图片上传分享软件极速,云服务器,永久储存,永不删除,图片支持外链,永久保存,无水印!无广告、无插件、无病毒,完全免费软件。 允许上传的文件类型为:jpg|jpeg|gif|bmp|png|swf|mp3|wma|zip|rar|doc 图酷...
1.可用于移动端H5 2.可用于小程序webview,用于替代wx.uploadFile的技术...4.设置的格式支持MP3,WAV可自己调整 5.如果后端接收到的tmp_name为空,请检查服务端允许上传的文件大小,比如PHP.ini的upload_max_filesize
FCKeditor是款强大的在线编辑工具,网站后台怎么少了它!...图片预览: http://home.iopq.com/attachment/201010/13/685312_12869582950zf2.jpg http://home.iopq.com/attachment/201010/13/685312_1286959387OZDM.jpg ...
对MP3文件的ID3信息解析,支持包含图片的MP3,另外用QT作了一个UI,另外打包上传
实现文件的上传和下载的功能,支持图片,MP3,word,excel等。
asp上传文件完整版。。。 添删改查。。。 删除也会删除数据库对应的记录,以及对应的文件夹中的图片
mp3文件加入封面!!你会喜欢的,手机克显示歌曲专辑封面!!!
封装波形声音文件(wav文件)和MP3文件的加载、播放、暂停、定位等声音文件的操作等。 注:此上传本版为压缩资源版,原始版100M以上(实在对不住大家,上传大小限制,没办法呀)。 另外:在res里面带有地图生成器的...
连连看路径两种快速搜索算法;...封装波形声音文件(wav文件)和MP3文件的加载、播放、暂停、定位等声音文件的操作等。 注:此上传本版为压缩资源版,原始版100M以上(实在对不住大家,上传大小限制,没办法了) ...
$uptypes=array(‘image/jpg’, //上传文件类型列表 ‘image/jpeg’, ‘image/png’, ‘image/pjpeg’, ‘image/gif’, ‘image/bmp’, ‘application/x-shockwave-flash’, ‘image/x-png’, ‘application/msword...