当前位置:网站首页>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
边栏推荐
- bonecp使用数据源
- [Android] kotlin code writing standardization document
- Compilation principle - top-down analysis and recursive descent analysis construction (notes)
- C语言自动预订飞机票问题
- UFIDA OA vulnerability learning - ncfindweb directory traversal vulnerability
- FMT open source self driving instrument | FMT middleware: a high real-time distributed log module Mlog
- Cocos2d Lua 越来越小样本 内存游戏
- Tree-LSTM的一些理解以及DGL代码实现
- Redis的五种数据结构
- win10系统下插入U盘有声音提示却不显示盘符
猜你喜欢
随机推荐
Codeforces Round #803 (Div. 2)
Reproduce ThinkPHP 2 X Arbitrary Code Execution Vulnerability
2022 Summer Project Training (II)
Blue Bridge Cup real question: one question with clear code, master three codes
[swoole series 2.1] run the swoole first
随着MapReduce job实现去加重,多种输出文件夹
文档编辑之markdown语法(typora)
MySQL查询请求的执行过程——底层原理
UDP protocol: simple because of good nature, it is inevitable to encounter "city can play"
TOP命令详解
【Swoole系列2.1】先把Swoole跑起来
C language exchanges two numbers through pointers
The latest financial report release + tmall 618 double top, Nike energy leads the next 50 years
STM32 key state machine 2 - state simplification and long press function addition
Splay
Four processes of program operation
A method of sequentially loading Unity Resources
【.NET CORE】 请求长度过长报错解决方案
Running the service with systemctl in the container reports an error: failed to get D-Bus connection: operation not permitted (solution)
STM32+ESP8266+MQTT协议连接OneNet物联网平台




![[.Net core] solution to error reporting due to too long request length](/img/62/6bdc43885f9be3fa4538276c0dc122.png)



