当前位置:网站首页>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
边栏推荐
- On time and parameter selection of asemi rectifier bridge db207
- Introduction to the usage of model view delegate principal-agent mechanism in QT
- 递归的方式
- HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother
- Declval of template in generic programming
- STM32+MFRC522完成IC卡号读取、密码修改、数据读写
- The third season of Baidu online AI competition is coming in midsummer, looking for you who love AI!
- Windows连接Linux上安装的Redis
- Reproduce ThinkPHP 2 X Arbitrary Code Execution Vulnerability
- C language exchanges two numbers through pointers
猜你喜欢
递归的方式
Recursive way
从交互模型中蒸馏知识!中科大&美团提出VIRT,兼具双塔模型的效率和交互模型的性能,在文本匹配上实现性能和效率的平衡!...
SAP Fiori 应用索引大全工具和 SAP Fiori Tools 的使用介绍
Declval (example of return value of guidance function)
Four processes of program operation
I want to say more about this communication failure
阿里云国际版ECS云服务器无法登录宝塔面板控制台
Ms-tct: INRIA & SBU proposed a multi-scale time transformer for motion detection. The effect is SOTA! Open source! (CVPR2022)...
图之广度优先遍历
随机推荐
使用block实现两个页面之间的传统价值观
The latest financial report release + tmall 618 double top, Nike energy leads the next 50 years
High precision operation
Jerry's watch reading setting status [chapter]
Jerry is the custom background specified by the currently used dial enable [chapter]
UFIDA OA vulnerability learning - ncfindweb directory traversal vulnerability
Jielizhi obtains the customized background information corresponding to the specified dial [chapter]
Echart simple component packaging
celery最佳实践
【剑指 Offer】 60. n个骰子的点数
The third season of Baidu online AI competition is coming in midsummer, looking for you who love AI!
Four processes of program operation
[Android] kotlin code writing standardization document
Alibaba cloud international ECS cannot log in to the pagoda panel console
SQL优化问题的简述
【LeetCode第 300 场周赛】
POJ 2208 已知边四面体六个长度,计算体积
287. Find duplicates
虚拟机VirtualBox和Vagrant安装
解读云原生技术