I am working with an iOS application in which I have to upload images on Box Service. After authentication process when I uploaded images from the NSBundle, it uploaded successfully.
when I uploaded from a path image get uploaded but only file is created, no data is uploaded.
Below is my uploaded method:
-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];
}
I am getting the output, but my file is not uploaded with data, only an image of file with name created. I am getting following output in log:
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] inputStream DIRECT : <__NSCFInputStream: 0x7f8f7ae5db00>
2014-08-19 17:25:58.432 BoxSDKSampleApp[17252:1243051] The operation couldn’t be completed. (Cocoa error 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
Please help me out, as per my knowledge I think I am doing any mistake in reading the file from path and sending to NSinputstream. Please help me out. Thank you