2013-10-28 58 views
0

我試圖在我的iOS應用程序中使用box-api-2編輯txt文件。Box api編輯文件

我試試這個代碼,其中filedata - NSData與NSString,應該替換文件。

BoxFilesRequestBuilder *builder = [[BoxFilesRequestBuilder alloc] init]; 
builder.name = self.previewFile.name; 
builder.parentID = self.folderID; 
NSInputStream *inputStream = [NSInputStream inputStreamWithData:fileData]; 
long long contentLength = [fileData length]; 
[[BoxSDK sharedSDK].filesManager overwriteFileWithID:self.previewFile.modelID inputStream:inputStream contentLength:contentLength requestBuilder:builder success:^(BoxFile *file) { 
    NSLog(@"Yeahh"); 
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSDictionary *JSONDictionary) { 
    NSLog(@"%@", [error description]); 
}]; 
RELEASE_SAFELY(builder); 

但我得到了一個錯誤:

Error Domain=com.box.sdk.errordomain Code=405 "The operation couldn’t be completed. (com.box.sdk.errordomain error 405.)" UserInfo=0x1e11b5a0 {com.box.sdk.jsonerrorresponse=<CFBasicHash 0x1e2e0460 [0x3c6e6100]>{type = immutable dict, count = 6, 
entries => 
    0 : <CFString 0x1e04b520 [0x3c6e6100]>{contents = "type"} = <CFString 0x1e2e5340 [0x3c6e6100]>{contents = "error"} 
    1 : <CFString 0x3c6cfc94 [0x3c6e6100]>{contents = "status"} = <CFNumber 0x1e289df0 [0x3c6e6100]>{value = +405, type = kCFNumberSInt64Type} 
    2 : <CFString 0x1e2e2ea0 [0x3c6e6100]>{contents = "code"} = <CFString 0x1e2c1620 [0x3c6e6100]>{contents = "method_not_allowed"} 
    3 : <CFString 0x1e28b140 [0x3c6e6100]>{contents = "help_url"} = <CFString 0x1e2defc0 [0x3c6e6100]>{contents = "http://developers.box.com/docs/#errors"} 
    4 : <CFString 0x1e2e2dd0 [0x3c6e6100]>{contents = "request_id"} = <CFString 0x1e2e2df0 [0x3c6e6100]>{contents = "417724859526e752ff250a"} 
    5 : <CFString 0x1e28b160 [0x3c6e6100]>{contents = "message"} = <CFString 0x1e2e2db0 [0x3c6e6100]>{contents = "Method Not Allowed"} 
} 

回答

1

我箱的iOS SDK的維護者。在builder.name(或生成器)爲nil的情況下,我能夠重現此錯誤。你確定self.previewFile.name已設置嗎?

在任何情況下,對於覆蓋,這應該無關緊要,因爲V2 API不會對文件覆蓋進行重命名(它只會更新文件的內容)。

http://developers.box.com/docs/#files-upload-a-new-version-of-a-file

The filename on Box will remain the same as the previous version. To update the file’s name, use PUT /files/{id}

我已經推了錯誤修正到GitHub上,設置一個默認文件名多上傳,如果一個不存在,它應該允許上傳開去。 https://github.com/box/box-ios-sdk-v2/releases/tag/v1.1.2

新的podspec即將推出。

+0

你說得對,self.previewFile錯了。謝謝。 – Dmitriy