asi POST 图片批量上传,求Demo,接口是

Forever_淡陌 发布于 2014/10/12 08:27
阅读 562
收藏 0
传入参数:
user_id     用户ID
act_id       活动ID
act_photo_list      图片文件数组(多个图片上传)
加载中
0
Forever_淡陌
Forever_淡陌

跪求大神帮忙,都困扰我几天了,每次都是选中了几张图片,最后只上传了一张

NSString *url = [HTTP stringByAppendingFormat:@"sendPhoto"];


    NSURL *urlpath = [NSURL URLWithString:url];

    ASIFormDataRequest *request = [[ASIFormDataRequest alloc]initWithURL:urlpath];

    

    

    [request setPostValue:self.user.str_user_id forKey:@"user_id"];

    [request setPostValue:self.activity.str_actId forKey:@"act_id"];

    

   // [request setPostValue:_data forKey:@"act_photo_list"];

    if (arr.count == 0)

    {

        

    }

    else

    {

        for (int i = 0; i < arr.count; i++)

        {

            ALAsset *asset = [arr objectAtIndex:i];

            // NSURL *url = [[asset defaultRepresentation]url];

            CGImageRef ref = [[asset defaultRepresentation]fullScreenImage];

            UIImage *im = [[UIImage alloc]initWithCGImage:ref];

            //img.image = im;

            NSData *imgData = UIImageJPEGRepresentation(im, 0.7);

            NSString *filePath = [NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES)lastObject];

            filePath = [filePath stringByAppendingFormat:@"%@.jpeg",[AppClient getNowTime]];

            [imgData writeToFile:filePath atomically:YES];

            [request addFile:filePath forKey:@"act_photo_list"];

           // [_data appendData:imgData];

            

            [request addData:imgData withFileName:@"aa.jpeg" andContentType:@"image/jpeg" forKey:@"act_photo_list"];

            

        }

    }

    __strong ASIFormDataRequest *weakRequest = request;

    [request setDelegate:self];

    [request setRequestMethod:@"POST"];

    [request buildRequestHeaders];

    [request startAsynchronous];

0
Forever_淡陌
Forever_淡陌
,求大神指导
返回顶部
顶部