how to upload image file from document directory to php server in iphone

后端 未结 4 657
别那么骄傲
别那么骄傲 2021-01-17 04:04

I am currently working on gallery kind of iPhone application. According to my requirement, i need to store all the camera captured image into document directory. there is so

4条回答
  •  再見小時候
    2021-01-17 05:01

    Here is my sample code

     NSURL *nsurl =[NSURL URLWithString:urlString];  
     NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:nsurl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];   
     [request setURL:nsurl];  
     [request setHTTPMethod:@"POST"];  
    
    
     NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];  
     NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];  
     [request addValue:contentType forHTTPHeaderField: @"Content-Type"];  
    
     NSMutableData *body = [NSMutableData data];  
    
     //Image  
     [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"image\"; filename=\"%@\"\r\n",[fileName text]] dataUsingEncoding:NSUTF8StringEncoding]];  
     [body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];  
     [body appendData:[NSData dataWithData:imageData]];  
     [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];  
    
     // setting the body of the post to the reqeust  
     [request setHTTPBody:body];  
    
    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];  
    

提交回复
热议问题