我一直在試用一段時間,使用Box 2.0 API
從Objective C客戶端上傳文件到我的Box文件夾。我讀過從幾個帖子:使用目標C框文件上傳API
- how to send form data in a programmatic file upload in box api 2.0
- API 2.0 how to upload file with POSTMAN?
我使用Curl
成功嘗試,如文檔中提到,但試圖創建時總能得到404一個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"];
請不要在論壇帖子上發佈api_key和auth_tokens類似於發佈您的用戶名和密碼。我將建議您編輯您的評論,提取詳細信息,並在Box上使您的授權令牌無效。 – Peter
忘記這個圖書館傢伙 - http://allseeing-i.com/%5Brequest_release%5D :) – h4cky