当前位置:网站首页>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
边栏推荐
- 287. Find duplicates
- Insert dial file of Jerry's watch [chapter]
- MS-TCT:Inria&SBU提出用于动作检测的多尺度时间Transformer,效果SOTA!已开源!(CVPR2022)...
- [swoole series 2.1] run the swoole first
- 关于这次通信故障,我想多说几句…
- STM32+HC05串口蓝牙设计简易的蓝牙音箱
- Introduction and case analysis of Prophet model
- 简单易用的PDF转SVG程序
- 用友OA漏洞学习——NCFindWeb 目录遍历漏洞
- F200 - UAV equipped with domestic open source flight control system based on Model Design
猜你喜欢

win10系统下插入U盘有声音提示却不显示盘符

Top command details

30 minutes to understand PCA principal component analysis

Distiller les connaissances du modèle interactif! L'Université de technologie de Chine & meituan propose Virt, qui a à la fois l'efficacité du modèle à deux tours et la performance du modèle interacti

UDP protocol: simple because of good nature, it is inevitable to encounter "city can play"

【.NET CORE】 请求长度过长报错解决方案

Tree-LSTM的一些理解以及DGL代码实现

2019 Alibaba cluster dataset Usage Summary

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

std::true_ Type and std:: false_ type
随机推荐
Comparative examples of C language pointers *p++, * (p++), * ++p, * (++p), (*p) + +, +(*p)
Redis的五种数据结构
Transfer data to event object in wechat applet
Release of the sample chapter of "uncover the secrets of asp.net core 6 framework" [200 pages /5 chapters]
Cocos2d Lua 越来越小样本 内存游戏
当保存参数使用结构体时必备的开发技巧方式
Shangsilicon Valley JUC high concurrency programming learning notes (3) multi thread lock
Jerry's setting currently uses the dial. Switch the dial through this function [chapter]
[swoole series 2.1] run the swoole first
ADB common commands
High precision operation
第三季百度网盘AI大赛盛夏来袭,寻找热爱AI的你!
2022暑期项目实训(二)
随着MapReduce job实现去加重,多种输出文件夹
[.Net core] solution to error reporting due to too long request length
Excel usage record
阿里云国际版ECS云服务器无法登录宝塔面板控制台
Docker安装Redis
DOM简要
Easy to use PDF to SVG program