美文网首页
图片上传

图片上传

作者: 飞鱼ll | 来源:发表于2018-08-06 21:33 被阅读8次

    base64

    NSMutableDictionary *paraDic = [[NSMutableDictionary alloc]init];
    [paraDic setObject:[@"data:img/jpg;base64," stringByAppendingString:[_imageData base64EncodedString]] forKey:@"data"];
    [paraDic setObject:@"tmp" forKey:@"filename"];
    [paraDic setObject:@(_imageData.length) forKey:@"size"];
    

    文件

        NSData *data = UIImageJPEGRepresentation(image, 0.9);
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        manager.responseSerializer = [AFJSONResponseSerializer serializer];
        [manager POST:@"https://sm.ms/api/upload" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
            [formData appendPartWithFileData:data name:@"smfile" fileName:@"temp" mimeType:@"image/jpg"];
        } progress:^(NSProgress * _Nonnull uploadProgress) {
            NSLog(@"%f", uploadProgress.fractionCompleted);
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
    
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        }];
    

    相关文章

      网友评论

          本文标题:图片上传

          本文链接:https://www.haomeiwen.com/subject/pehnvftx.html