Box Service に画像をアップロードする必要がある iOS アプリケーションを使用しています。NSBundle から画像をアップロードする際の認証プロセスの後、正常にアップロードされました。パス画像からアップロードするとアップロードされますが、ファイルのみが作成され、データはアップロードされません。
以下は私のアップロードされた方法です:
-m(void)uploadimages:(UIImage*)image
{
BoxFileBlock fileBlock = ^(BoxFile *file)
{
[self fetchFolderItemsWithFolderID:self.folderID name:self.navigationController.title];
dispatch_sync(dispatch_get_main_queue(), ^{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"File Upload Successful" message:[NSString stringWithFormat:@"File has id: %@", file.modelID] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
});
};
BoxAPIJSONFailureBlock failureBlock = ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSDictionary *JSONDictionary)
{
BOXLog(@"status code: %li", (long)response.statusCode);
BOXLog(@"upload response JSON: %@", JSONDictionary);
};
BoxFilesRequestBuilder *builder = [[BoxFilesRequestBuilder alloc] init];
NSInteger randomNumber = arc4random() % 100;
NSString *filename = [NSString stringWithFormat:@"PicBackMan-%ld.jpg",(long)randomNumber];
builder.name = filename;
builder.parentID = self.folderID;
NSLog(@"builder.parentID : %@",builder.parentID);
NSArray *pathList = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,
YES);
path = [[pathList objectAtIndex:0] stringByAppendingPathComponent:@"image.jpg"];
NSLog(@"Path o/p is %@",path);
NSInputStream *inputStream = [NSInputStream inputStreamWithFileAtPath: path];
NSLog(@"inputStream DIRECT : %@",inputStream);
NSError *error;
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:&error];
if (!error) {
if (fileAttributes != nil) {
NSLog(@"File attributes found.");
} else {
NSLog(@"File attributes not found.");
}
} else {
NSLog(@"%@", [error localizedDescription]);
long long contentLength = [[fileAttributes objectForKey:NSFileSize] longLongValue];
NSLog(@"fileAttributes : %@",fileAttributes);
NSLog(@"contentLength : %lld",contentLength);
[[BoxSDK sharedSDK].filesManager uploadFileWithInputStream:inputStream contentLength:contentLength MIMEType:nil requestBuilder:builder success:fileBlock failure:failureBlock progress:nil];
}
出力を取得していますが、ファイルはデータとともにアップロードされず、名前が作成されたファイルの画像のみがアップロードされます。ログに次の出力が表示されます。
builder.parentID : 2323165189
2014-08-19 17:25:58.431 BoxSDKSampleApp[17252:1243051] /Users/bettermac9/Library/Application Support/iPhone Simulator/7.1-64/Applications/30DFB367-599B-4F39-AD62-D27B1081FE99/Documents/image.jpg
2014-08-19 17:25:58.432 BoxSDKSampleApp[17252:1243051] 入力ストリーム ダイレクト: <__NSCFInputStream: 0x7f8f7ae5db00>
2014-08-19 17:25:58.432 BoxSDKSampleApp[17252:1243051] 操作を完了できませんでした。(ココア エラー 260)
2014-08-19 17:25:58.432 BoxSDKSampleApp[17252:1243051] fileAttributes: (null)
2014-08-19 17:25:58.432 BoxSDKSampleApp[17252:1243051] contentLength: 0
私の知る限り、パスからファイルを読み取って NSinputstream に送信する際に間違いを犯していると思います。私を助けてください。ありがとうございました