我一直在尝试Box 2.0 API
将文件从 Objective C 客户端上传到我的 Box 文件夹。我读过以下几篇文章:
如文档中所述,我已尝试成功使用Curl
.,但在尝试创建NSMutableUrlRequest
. 这是我的代码:
NSURL *URL = [NSURL URLWithString:@"https://api.box.com/2.0/files/content"];
urlRequest = [[NSMutableURLRequest alloc]
initWithURL:URL cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:30];
[urlRequest setHTTPMethod:@"POST"];
AppDelegate *appDelegate = [AppDelegate sharedDelegate];
NSString *p = [NSString stringWithFormat:@"BoxAuth api_key=%@&auth_token=%@",API_KEY,appDelegate.boxAuthToken];
[urlRequest setValue:p forHTTPHeaderField:@"Authorization"];
[urlRequest setValue:@"multipart/form-data, boundary=AaB03x" forHTTPHeaderField:@"Content-Type"];
NSString *postBody = @"--AaB03x"
@"content-disposition: form-data; name=\"filename\"; filename=\"test.txt\";"
@"folder_id=466838434"
@"Content-type: text/plain"
@""
@"testing box api 2.0"
@""
@"--AaB03x--";
NSData *data = [postBody dataUsingEncoding:NSUTF8StringEncoding];
[urlRequest setHTTPBody:data];
[urlRequest setValue:[NSString stringWithFormat:@"%d",[data length]] forHTTPHeaderField:@"Content-Length"];