当前位置:网站首页>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
边栏推荐
- Rb157-asemi rectifier bridge RB157
- 随着MapReduce job实现去加重,多种输出文件夹
- MySQL查询请求的执行过程——底层原理
- D binding function
- Transport layer congestion control - slow start and congestion avoidance, fast retransmission, fast recovery
- FMT open source self driving instrument | FMT middleware: a high real-time distributed log module Mlog
- 测试123
- 1700C - Helping the Nature
- Prophet模型的简介以及案例分析
- 30 minutes to understand PCA principal component analysis
猜你喜欢
Comparative examples of C language pointers *p++, * (p++), * ++p, * (++p), (*p) + +, +(*p)
Transport layer congestion control - slow start and congestion avoidance, fast retransmission, fast recovery
Ms-tct: INRIA & SBU proposed a multi-scale time transformer for motion detection. The effect is SOTA! Open source! (CVPR2022)...
Grafana 9.0 正式发布!堪称最强!
win10系统下插入U盘有声音提示却不显示盘符
The third season of Baidu online AI competition is coming in midsummer, looking for you who love AI!
Declval of template in generic programming
小程序在产业互联网中的作用
Penetration test information collection - CDN bypass
MySQL查询请求的执行过程——底层原理
随机推荐
Introduction to the usage of model view delegate principal-agent mechanism in QT
具体说明 Flume介绍、安装和配置
Numerical analysis: least squares and ridge regression (pytoch Implementation)
Jielizhi obtains the customized background information corresponding to the specified dial [chapter]
Automatic reservation of air tickets in C language
MS-TCT:Inria&SBU提出用于动作检测的多尺度时间Transformer,效果SOTA!已开源!(CVPR2022)...
Will openeuler last long
Tree-LSTM的一些理解以及DGL代码实现
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
2022暑期项目实训(三)
Blue Bridge Cup real question: one question with clear code, master three codes
CSRF vulnerability analysis
High precision operation
Markdown grammar - better blogging
287. Find duplicates
文档编辑之markdown语法(typora)
测试1234
Reprint: defect detection technology of industrial components based on deep learning
Splay
Redis的五种数据结构