Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-11-2011, 01:49 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default Dropbox Error 1001

I still can't figure out how to get a file to upload to Dropbox.

I'm using their new SDK and following their instructions but I'm still getting the error 1001.

What does this mean exactly?

I also know that I am getting a null value on what I am trying to send. Here's some of my code. Am I missing something?

Code:
- (void)didPressLink
{
    if (![[DBSession sharedSession] isLinked]) 
    {
        [[DBSession sharedSession] link];
    }
}

- (DBRestClient *)restClient 
{
    if (!restClient) 
    {
        restClient = 
        [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
        restClient.delegate = self;
    }
    return restClient;
}

- (void)uploadFile:(DBRestClient *)client
{
    NSMutableData * pdfData = [NSMutableData data];
    UIGraphicsBeginPDFContextToData(pdfData, self.view.bounds, nil);
    UIGraphicsBeginPDFPage();
    CGContextRef pdfContext = UIGraphicsGetCurrentContext();
    [self.view.layer renderInContext:pdfContext];
    UIGraphicsEndPDFContext();
        //Not sure if this is the right way to send a PDF file????
    //NSString * testString = [[NSString alloc] initWithData:pdfData encoding:NSUTF8StringEncoding];

    //Trying to just send a basic file here
    NSString * testString = @"Hello World";
    NSString * local = [[NSString alloc] initWithString:testString];

    //NSString *localPath = [[NSBundle mainBundle] pathForResource:testString ofType:@"txt"];
    //NSString *filename = @"test.pdf";

    NSString *destDir = @"/";

    [restClient uploadFile:testString toPath:destDir withParentRev:nil fromPath:local];
}

- (void)restClient:(DBRestClient*)client uploadedFile:(NSString*)destPath
              from:(NSString*)srcPath metadata:(DBMetadata*)metadata {
    
    NSLog(@"File uploaded successfully to path: %@", metadata.path);
}

- (void)restClient:(DBRestClient*)client uploadFileFailedWithError:(NSError*)error {
    NSLog(@"File upload failed with error - %@", error);
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [dropBoxButton addTarget:self action:@selector(didPressLink) forControlEvents:UIControlEventTouchUpInside];
    [uploadButton addTarget:self action:@selector(uploadFile:) forControlEvents:UIControlEventTouchUpInside];
}
Thanks for the help!
lukeirvin is offline   Reply With Quote
Old 11-13-2011, 04:04 AM   #2 (permalink)
Registered Member
 
apatsufas's Avatar
 
Join Date: Jan 2011
Location: Thessaloniki, Greece
Posts: 121
apatsufas is on a distinguished road
Default

You are just trying to send an NSString thats with you get en error. You need to save the pdf or txt file to disk and then pass the path to that file to dropbox.
__________________
SQLed - Your Database Manager on the go

iAZConverter - Converts everything from A to Z
apatsufas is offline   Reply With Quote
Old 11-14-2011, 10:44 AM   #3 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default

This is what I am trying now:

Code:
- (NSString *)getDocumentPath
{ 
    NSMutableData * pdfData = [NSMutableData data];
    UIGraphicsBeginPDFContextToData(pdfData, self.view.bounds, nil);
    UIGraphicsBeginPDFPage();
    CGContextRef pdfContext = UIGraphicsGetCurrentContext();
    [self.view.layer renderInContext:pdfContext];
    UIGraphicsEndPDFContext();
    
    NSString * pdfString = [[NSString alloc] initWithData:pdfData encoding:NSUTF8StringEncoding];
    
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	
	NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:pdfString];
	
	return path;  
}
Code:
- (IBAction)uploadFile:(id)sender
{
    NSString *path = [self getDocumentPath];
    
    NSString * local = [[NSString alloc] initWithString:path];
    //NSString *localPath = [[NSBundle mainBundle] pathForResource:path ofType:@"pdf"];
    NSString *destDir = @"/";

    [restClient uploadFile:local toPath:destDir withParentRev:nil fromPath:path];
}
pdfString is coming back nil though. Am I on the right path here or how should I store the pdfData into a string? Or should it be stored into a string to store it into the path?

I'm just a bit confused on this.
lukeirvin is offline   Reply With Quote
Old 11-14-2011, 11:43 AM   #4 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default

My NSString in my uploadFile method always comes back NULL no matter what I try.

What's the proper way to set NSData to an NSString?
lukeirvin is offline   Reply With Quote
Old 11-15-2011, 04:18 AM   #5 (permalink)
Registered Member
 
apatsufas's Avatar
 
Join Date: Jan 2011
Location: Thessaloniki, Greece
Posts: 121
apatsufas is on a distinguished road
Default

You are still not creating the pdf file. You need to create a file in order to upload it. You are just trying to send a string. That won't work.

Try this

Code:
- (NSString *)getDocumentPath
{ 
    NSMutableData * pdfData = [NSMutableData data];
    UIGraphicsBeginPDFContextToData(pdfData, self.view.bounds, nil);
    UIGraphicsBeginPDFPage();
    CGContextRef pdfContext = UIGraphicsGetCurrentContext();
    [self.view.layer renderInContext:pdfContext];
    UIGraphicsEndPDFContext();
    
    
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	
	NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"yourfilename.pdf"];
	
	[pdfData writeToFile:path  atomically:YES];

	return path;  
}

- (IBAction)uploadFile:(id)sender
{
    NSString *path = [self getDocumentPath];
    
    NSString * local = [path lastPathComponent];
   
    NSString *destDir = @"/";

    [restClient uploadFile:local toPath:destDir withParentRev:nil fromPath:path];
}
__________________
SQLed - Your Database Manager on the go

iAZConverter - Converts everything from A to Z
apatsufas is offline   Reply With Quote
Old 11-15-2011, 08:52 AM   #6 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default

ahh, this makes much more sense than what I was trying. Thank you much.

I can see in my Debugger that all of this is working. But these are not getting called at all:

Code:
- (void)restClient:(DBRestClient*)client uploadedFile:(NSString*)destPath
              from:(NSString*)srcPath metadata:(DBMetadata*)metadata 
{
    NSString * filename = [[srcPath pathComponents] lastObject];
    NSLog(@"Uploaded file %@", filename);
    NSLog(@"File uploaded successfully to path: %@", metadata.path);
}

- (void)restClient:(DBRestClient*)client uploadFileFailedWithError:(NSError*)error {
    NSLog(@"File upload failed with error - %@", error);
}
lukeirvin is offline   Reply With Quote
Old 11-15-2011, 09:31 AM   #7 (permalink)
Registered Member
 
apatsufas's Avatar
 
Join Date: Jan 2011
Location: Thessaloniki, Greece
Posts: 121
apatsufas is on a distinguished road
Default

Did you set the delegate for restClient to your viewcontroller?

Code:
restClient.delegate = self;
__________________
SQLed - Your Database Manager on the go

iAZConverter - Converts everything from A to Z
apatsufas is offline   Reply With Quote
Old 11-15-2011, 09:36 AM   #8 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default

Yes. Still not working though.
lukeirvin is offline   Reply With Quote
Old 11-15-2011, 10:55 AM   #9 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default

looks like restClient and session are both showing 0x0 in the Debug Window.
lukeirvin is offline   Reply With Quote
Old 11-15-2011, 11:01 AM   #10 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default

Changed one line of code and now I'm getting this error

Code:
[WARNING] DropboxSDK: error making request to /1/files_put/sandbox/test.pdf - Error Domain=dropbox.com Code=502 "The operation couldn’t be completed. (dropbox.com error 502.)"
lukeirvin is offline   Reply With Quote
Old 11-15-2011, 11:17 AM   #11 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default

I've got it fixed and working!

Not sure what I was getting that error but I commented out a couple of lines I wasn't using and removed all break points. Ran the app again and it worked!

My file was uploaded successfully to my Dropbox.

Just need to add in a HUD and a few other things!


Thank you so much for your help. I appreciate it a lot!
lukeirvin is offline   Reply With Quote
Old 11-15-2011, 10:47 PM   #12 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default

What would be the proper way to Login to Dropbox and Upload a file through one method?
lukeirvin is offline   Reply With Quote
Old 11-16-2011, 12:42 AM   #13 (permalink)
Registered Member
 
apatsufas's Avatar
 
Join Date: Jan 2011
Location: Thessaloniki, Greece
Posts: 121
apatsufas is on a distinguished road
Default

It is not possible to do this from one method.

If your using the new Dropbox sdk which does the login in the Dropbox app or in safari you could create a protocol in your apps delegate and then connect your viewcontroller to that.

Here is what I do
Code:
#MyAppDelegate.h

@protocol DropBoxLoginDelegate <NSObject>

- (void)logedIn;

@end

@interface MyAppDelegate : NSObject{
...
...
id<DropBoxLoginDelegate>_dropBoxDelegate;
}

...
...

@property (assign) id<DropBoxLoginDelegate> dropBoxDelegate;


#MyAppDelegate.m

@implementation MyAppDelegate

@synthesize dropBoxDelegate = _dropBoxDelegate;

...
...

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
    
    if ([[DBSession sharedSession] handleOpenURL:url]) {
        if ([[DBSession sharedSession] isLinked]) {
            NSLog(@"App linked successfully!");
            [self.dropBoxDelegate logedIn];
            // At this point you can start making API calls
        }
        return YES;
    }


MyViewController.h

@interface basedbDetailedViewController : UITableViewController<DropBoxLoginDelegate>{
...
...

- (void)viewDidLoad
{
    MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
    
    appDelegate.dropBoxDelegate = self;

...
...
}

- (void)logedIn{
   //Here goes your code for uploading the file
}
__________________
SQLed - Your Database Manager on the go

iAZConverter - Converts everything from A to Z
apatsufas is offline   Reply With Quote
Old 11-16-2011, 09:41 AM   #14 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default

Brilliant. Makes perfect sense. Thank you so much.
lukeirvin is offline   Reply With Quote
Old 11-18-2011, 01:07 PM   #15 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default

One last question...

I built a sample app to make sure this works and it does. Works just how I want it too.

I have added this code into my app that will go live and Dropbox is not fully working.

I was able to open Dropbox, log in and allow Dropbox to use this app. A new folder was made in my Dropbox account. But my file is not being uploaded at all.

I don't even think the restClient is being called. I've set some breakpoints and it just gets skipped over. Any thoughts on why this would happen?
lukeirvin is offline   Reply With Quote
Old 11-18-2011, 01:43 PM   #16 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default

Code:
- (IBAction)didPressLink
{
    if (![[DBSession sharedSession] isLinked]) 
    {
        [[DBSession sharedSession] link];
    }
}
The issue is here. If I step through this it skips [[DBSession sharedSession] link];

What causes this?
lukeirvin is offline   Reply With Quote
Old 11-18-2011, 03:56 PM   #17 (permalink)
Registered Member
 
apatsufas's Avatar
 
Join Date: Jan 2011
Location: Thessaloniki, Greece
Posts: 121
apatsufas is on a distinguished road
Default

Your app has been linked to Dropbox so there is no need to call the link function.
The problem is not in that code. It must be somewhere else.
__________________
SQLed - Your Database Manager on the go

iAZConverter - Converts everything from A to Z
apatsufas is offline   Reply With Quote
Old 11-18-2011, 04:22 PM   #18 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default

Correct. The problem is here I believe

Code:
- (DBRestClient *)restClient 
{
//    if (!restClient) 
//    {
//        restClient = 
//        [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
//        restClient.delegate = self;
//    }
    restClient = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
    restClient.delegate = self;
    return restClient;
    NSLog(@"%@", restClient);
}
The commented code was the original but when I changed it to get rid of the if statement it worked great.

Only problem is... it worked that one time. Now I'm back to where I was. It's not getting called.
lukeirvin is offline   Reply With Quote
Old 11-19-2011, 12:34 AM   #19 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default

My code works but only once. And it only works if I completely remove the app then do a fresh install. What causes this?
lukeirvin is offline   Reply With Quote
Old 11-20-2011, 02:06 AM   #20 (permalink)
Registered Member
 
apatsufas's Avatar
 
Join Date: Jan 2011
Location: Thessaloniki, Greece
Posts: 121
apatsufas is on a distinguished road
Default

Quote:
Originally Posted by lukeirvin View Post
My code works but only once. And it only works if I completely remove the app then do a fresh install. What causes this?
I'm not exactly sure.

Do you set up Dropbox correctly in you apps Delegate ? In your application didFinishLaunching method you should have something like this

Code:
DBSession* dbSession = [[DBSession alloc] initWithAppKey:appKey appSecret:appSecret root:kDBRootAppFolder];
    
    [DBSession setSharedSession:dbSession];
    
    [dbSession release];
__________________
SQLed - Your Database Manager on the go

iAZConverter - Converts everything from A to Z
apatsufas is offline   Reply With Quote
Old 11-20-2011, 09:32 AM   #21 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default

Yes I have that set up correctly.
lukeirvin is offline   Reply With Quote
Old 11-20-2011, 10:33 AM   #22 (permalink)
Registered Member
 
apatsufas's Avatar
 
Join Date: Jan 2011
Location: Thessaloniki, Greece
Posts: 121
apatsufas is on a distinguished road
Default

Could you post the code for the upload?
__________________
SQLed - Your Database Manager on the go

iAZConverter - Converts everything from A to Z
apatsufas is offline   Reply With Quote
Old 11-20-2011, 12:10 PM   #23 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default

Sure.

This is in my AppDelegate .h

Code:
@protocol DropBoxLoginDelegate <NSObject>

- (void)loggedIn;

@end

@property (assign) id<DropBoxLoginDelegate>dropBoxDelegate;
In my AppDelegate.m

Code:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    if ([[DBSession sharedSession] handleOpenURL:url]) {
        if ([[DBSession sharedSession] isLinked]) {
            NSLog(@"App linked successfully!");
            [self.dropBoxDelegate loggedIn];
            // At this point you can start making API calls
        }
        return YES;
    }
    // Add whatever other url handling code your app requires here
    return NO;
}
When the app launches users can input information, etc. then can they can go to the next view (this is done by presentModalViewController). Here they have the sharing options, one is Dropbox.

Here is my code for uploading

Code:
- (NSString *)getDocumentPath
{
    shareToolBar.hidden = YES;
    NSMutableData * pdfData = [NSMutableData data];
    UIGraphicsBeginPDFContextToData(pdfData, self.view.bounds, nil);
    UIGraphicsBeginPDFPage();
    CGContextRef pdfContext = UIGraphicsGetCurrentContext();
    [resumeThemeOneView.layer renderInContext:pdfContext];
    UIGraphicsEndPDFContext();
    
    NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    
    NSString * path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Resume.pdf"];
    
    [pdfData writeToFile:path atomically:YES];
    
    shareToolBar.hidden = NO;
    
    return path;
    NSLog(@"%@", path);
}

- (void)loggedIn
{

    NSString * path = [self getDocumentPath];
    
    NSString * local = [path lastPathComponent];
    
    NSString * destDir = @"/";
    
    [[self restClient] uploadFile:local toPath:destDir withParentRev:nil fromPath:path];
}

- (void)restClient:(DBRestClient*)client uploadedFile:(NSString*)destPath
              from:(NSString*)srcPath metadata:(DBMetadata*)metadata 
{
    NSLog(@"File uploaded successfully to path: %@", metadata.path);
}

- (void)restClient:(DBRestClient*)client uploadFileFailedWithError:(NSError*)error 
{
    NSLog(@"File upload failed with error - %@", error);
}
And in my viewDidLoad

Code:
[restClient setDelegate:self];
    
   AppDelegate * appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    appDelegate.dropBoxDelegate = self;
The app still only works if I remove it and install it again. The Dropbox code works perfectly. But if I close the app and re-launch it, the Dropbox code is not getting called.
lukeirvin is offline   Reply With Quote
Old 11-20-2011, 12:55 PM   #24 (permalink)
Registered Member
 
apatsufas's Avatar
 
Join Date: Jan 2011
Location: Thessaloniki, Greece
Posts: 121
apatsufas is on a distinguished road
Default

I think I got it. How does the user select the Dropbox upload? From a button, actionsheet ? Because you are just uploading when the user links the app to Dropbox. Once the app is linked to Dropbox this

Code:
if ([[DBSession sharedSession] isLinked]) {
            NSLog(@"App linked successfully!");
            [self.dropBoxDelegate loggedIn];
            // At this point you can start making API calls
}
is not called.

So when lets say your button or actionsheet button is clicked you should check if the app is linked or not. If its not it will do what you do now but if its linked simply call

Code:
[self loggedIn];
__________________
SQLed - Your Database Manager on the go

iAZConverter - Converts everything from A to Z
apatsufas is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 400
16 members and 384 guests
7twenty7, Alex-alex, Apptronics RBC, baja_yu, chiataytuday, dre, gwelmarten, ipodphone, jeroenkeij, jleannex55, matador1978, mbadegree, n00b, pbart, Retouchable, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,125
Posts: 402,910
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:24 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0