asihttprequest上传图片

NSURL *url =@"yourURL";
    ASIFormDataRequest*currentRequest =[ASIFormDataRequest requestWithURL:url];
    [currentRequest setPostFormat:ASIMultipartFormDataPostFormat];[currentRequest setRequestMethod:@"POST"];
    [currentRequest addData:imgData withFileName:@"file" andContentType:@"image/png" forKey:@"yourFileNameOnServer"];//This would be the file name which is accepting image object on server side e.g. php page accepting file
    [currentRequest setDelegate:self];
    [currentRequest setDidFinishSelector:@selector(uploadImageFinished:)];
    [currentRequest setDidFailSelector:@selector(uploadImageFailed:)];
    [currentRequest startSynchronous];
    -(void)uploadImageFinished:(ASIHTTPRequest*)request
    {
        //Your request successfully executed. Handle accordingly.
    }
    -(void)uploadImageFailed:(ASIHTTPRequest*)request
        {//Your request failed to execute. Handle accordingly.
    }

 

你可能感兴趣的:(ASIHTTPRequest)