0

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

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Roshi
  • 41
  • 7
  • Are you sure "/Users/bettermac9/Library/Developer/CoreSimulator/Devices/198CEB7E-739C-43A7-919A-185404FF1FE4/data/Containers/Data/Application/029F0EAB-9F9A-484A-BAFC-EB30A5FA3C08/Documents/image.jpg" exists? – Marc-Alexandre Bérubé Aug 19 '14 at 12:22
  • @marc: sir i checked and found something wrong. Now my new path that i am getting is uRl o/p is /Users/bettermac9/Library/Application Support/iPhone Simulator/7.1-64/Applications/30DFB367-599B-4F39-AD62-D27B1081FE99/Documents/image.jpg sir i do not know why am getting fileAttributes "null" – Roshi Aug 19 '14 at 13:04
  • ios simulator file directory isn't always correct. Have you tried it from a device? – Jeevan Thandi Aug 19 '14 at 14:35
  • @jeevan : no sir i didn't tried from any device. i m doing with iOS Simulator only..but when i debug through terminal i got the image in that directory – Roshi Aug 19 '14 at 14:42

0 Answers0