2014-10-10 19 views
0

我不知道这如何检查用于通过POST传递self.request.get( “profile_pic”)从空目标C

这是通从目标C空

在Objective-C:

NSData *profile_pic_data = nil; (this does not change) 
... 
//Profile Pic Data 
[body appendData:[[NSString stringWithFormat:@"--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 
[body appendData:[@"Content-Disposition: form-data; name=\"profile_pic\"; filename=\"profile_pic.jpg\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; 
[body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; 
[body appendData:[NSData dataWithData:profile_pic_data]]; 
... 
NSLog(@"profile_pic_data = %@", profile_pic_data); //RETURNS (null) 

在Python:

... 
user_profile_pic_data = self.request.get("profile_pic") 
... 
if user_profile_pic_data: 
    #IT RUNS THIS CODE 
else: 
    #IT SHOULD RUN THIS CODE 

如果我打印出user_profile_pic_data它是由self.request.get( “profile_pic”)设定之后,在没有显示任何东西。

我曾尝试:

if user_profile_pic_data: 
if user_profile_pic_data is not NONE: 
if user_profile_pic_data is not NONE and != '': 

似乎没有任何工作。

任何人都会遇到这种情况?

回答

0

不知道正是你想在这里完成的,但在这里:

NSData *profile_pic_data = nil; 

你设置profile_pic_datanil。然后,您将您的POST数据附加到body,然后再次NSLogging profile_pic_data。既然你从来没有真正将它设置为nil以外的任何东西,这就是为什么它没有输出。

也许你想profile_pic_data实际上有内容?你可以从UIImage使用

NSData *profile_pic_data = UIImageJPEGRepresentation(anImage);