当前位置:网站首页>Afnetworking framework_ Upload file or image server
Afnetworking framework_ Upload file or image server
2022-07-06 18:26:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack .
The text of XXXXXXXXXX Fill in your argument more
– (void)uploadImageWithImage:(NSString *)imagePath
{
// Upload other required parameters
NSString *userId=XXXXXXXXXXX;
NSString *token=XXXXXXXXXXX;
// Upload request POST
AFHTTPClient *client=[AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@””]];
NSString *urlString=[NSString stringWithFormat:@” Upload server Address ];
NSDictionary *dic=[[NSDictionary alloc] initWithObjectsAndKeys:userId,@”XXXXXX”,token,@”XXXXXX”, nil];
NSURLRequest *request = [client multipartFormRequestWithMethod:@”POST” path:urlString parameters:dic constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
// Get the data you need to upload
NSData *data=[NSData dataWithContentsOfFile:imagePath];
// When uploading, use the current system event as the file name
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @”yyyyMMddHHmmss”;
NSString *str = [formatter stringFromDate:[NSDate date]];
NSString *fileName = [NSString stringWithFormat:@”%@.jpg”, str];
/*
This method parameter
1. To upload [ binary data ]
2. On the corresponding site [upload.php in ] Handling documents [ Field ”file”]
3. To keep in server Upper [ File name ]
4. Of uploaded files [mimeType]
*/
//server Fields and types of uploaded files
[formData appendPartWithFileData:data name:@”XXXXX” fileName:fileName mimeType:@”image/jpg/file”];
}];
// 3. operation Packaged urlconnetion
AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@” Upload finished ”);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@” Upload failed ->%@”, error);
}];
// function
[client.operationQueue addOperation:op];
}
Copyright notice : This article is an original blog article . Blog , Without consent , Shall not be reproduced .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/117393.html Link to the original text :https://javaforall.cn
边栏推荐
- 虚拟机VirtualBox和Vagrant安装
- Transport layer congestion control - slow start and congestion avoidance, fast retransmission, fast recovery
- 递归的方式
- Interview shock 62: what are the precautions for group by?
- Markdown grammar - better blogging
- Declval (example of return value of guidance function)
- C language exchanges two numbers through pointers
- node の SQLite
- Windows连接Linux上安装的Redis
- 从交互模型中蒸馏知识!中科大&美团提出VIRT,兼具双塔模型的效率和交互模型的性能,在文本匹配上实现性能和效率的平衡!...
猜你喜欢

Why does wechat use SQLite to save chat records?

Take you through ancient Rome, the meta universe bus is coming # Invisible Cities

模板于泛型编程之declval

Distill knowledge from the interaction model! China University of science and Technology & meituan proposed virt, which combines the efficiency of the two tower model and the performance of the intera

当保存参数使用结构体时必备的开发技巧方式

Docker安装Redis

关于这次通信故障,我想多说几句…

2019 Alibaba cluster dataset Usage Summary

Interesting - questions about undefined

Coco2017 dataset usage (brief introduction)
随机推荐
The latest financial report release + tmall 618 double top, Nike energy leads the next 50 years
STM32+HC05串口蓝牙设计简易的蓝牙音箱
【LeetCode第 300 场周赛】
Self-supervised Heterogeneous Graph Neural Network with Co-contrastive Learning 论文阅读
Markdown grammar - better blogging
Wchars, coding, standards and portability - wchars, encodings, standards and portability
TOP命令详解
使用block实现两个页面之间的传统价值观
图片缩放中心
Redis的五种数据结构
epoll()无论涉及wait队列分析
随着MapReduce job实现去加重,多种输出文件夹
Jielizhi obtains the currently used dial information [chapter]
win10系统下插入U盘有声音提示却不显示盘符
Interview shock 62: what are the precautions for group by?
十、进程管理
【中山大学】考研初试复试资料分享
2022 Summer Project Training (II)
C语言自动预订飞机票问题
44所高校入选!分布式智能计算项目名单公示