0

This is the method I used to authenticate my box and it opens a web view and I successfully got authenticated:

- (IBAction)box:(id)sender {     
                NSURL *authorizationURL = [BoxSDK sharedSDK].OAuth2Session.authorizeURL;
                NSString *redirectURI = [BoxSDK sharedSDK].OAuth2Session.redirectURIString;
                BoxAuthorizationViewController *authorizationViewController = [[BoxAuthorizationViewController alloc] initWithAuthorizationURL:authorizationURL redirectURI:redirectURI];
                BoxAuthorizationNavigationController *loginNavigation = [[BoxAuthorizationNavigationController alloc] initWithRootViewController:authorizationViewController];
                authorizationViewController.delegate = loginNavigation;
                loginNavigation.modalPresentationStyle = UIModalPresentationFormSheet;

                [self presentViewController:loginNavigation animated:YES completion:nil];

  }

After this process it returns to same view controller where I have a another action for upload (https://github.com/box/box-ios-sdk-sample-app):

- (IBAction)upload:(id)sender
{

        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:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alertView show];
            });
        };

        BoxAPIJSONFailureBlock failureBlock = ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSDictionary *JSONDictionary)
        {
            BOXLog(@"status code: %i", response.statusCode);
            BOXLog(@"upload response JSON: %@", JSONDictionary);
        };

        BoxFilesRequestBuilder *builder = [[BoxFilesRequestBuilder alloc] init];
        builder.name = @"image1.jpg";
        builder.parentID = self.folderID;


         NSString *path = [[NSBundle mainBundle] pathForResource:@"image1.jpg" ofType:nil];
        NSInputStream *inputStream = [NSInputStream inputStreamWithFileAtPath:path];
        NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil];
        long long contentLength = [[fileAttributes objectForKey:NSFileSize] longLongValue];

        [[BoxSDK sharedSDK].filesManager uploadFileWithInputStream:inputStream contentLength:contentLength MIMEType:nil requestBuilder:builder success:fileBlock failure:failureBlock progress:nil];
    }

After clicking upload button I receive this following message in console

Console error

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Ramanan R R
  • 896
  • 8
  • 18
  • Please update your question with actual text from the console (you can copy and paste the console output). It will be MUCH easier to read. – rmaddy Oct 11 '13 at 14:26
  • I think your code is missing MIME type parameter. You can see: http://stackoverflow.com/a/5998683/1322071 – Hoàng Toản Oct 11 '13 at 20:43

0 Answers0