We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
Chez B.
11 years agoNew member | Level 1
How do I upload a file to my dropbox apps folder in dropbox in objective c?
Currently nothing happens when I run my code.
This is how I am setting the up client. I did not put the client set up in my viewDidLoad method because this class will never be shown it just handles server side actions.
(instancetype)initWithClient
{
self = [super init];
if (self) {
self.restClient = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
self.restClient.delegate = self;
}
return self;
}
This is how I make the API call to upload
(void)uploadToDropBox:(UIImage *)img
{
NSLog(@"Entered the DB upload method");
NSArray *directories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,
YES);
NSString *documentDirectory = [directories firstObject];
NSString *imagePath = [documentDirectory stringByAppendingPathComponent:@"cardImage"];
NSString *destDir = @"Apps/BirthdayScrapbook";
NSLog(@"Just about to execute the upload method");
NSData *imageData = UIImagePNGRepresentation(img);
[imageData writeToFile:imagePath atomically: YES];
[self.restClient uploadFile:@"cardImage" toPath:destDir withParentRev:nil fromPath:imagePath];
NSLog(@"Executed the DB upload method");
[self sendBDayCard];
}
I think I am going about it wrong. I know what my access token is, but I don't know what to do with it nor where to put it. There is a client init method that takes in the userID, but I don't know where to find my accounts userID. Can someone give some direction with this?
17 Replies
Replies have been turned off for this discussion
- Chez B.11 years agoNew member | Level 1
How do I go about making sure that my account is linked properly? I am using the Facebook SDK in my app as well. Do you think it is a problem that I had to hack together (BOOL)application:(UIApplication *)app openURL:(NSURL *)url sourceApplication:(NSString *)source annotation:(id)annotation method in order to please both API's like this
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [FBAppCall handleOpenURL:url
sourceApplication:sourceApplication
withSession:[PFFacebookUtils session]] && [[DBSession sharedSession] handleOpenURL:url] && [[DBSession sharedSession] isLinked];
}
Instead of doing this like in the tutorial
- (BOOL)application:(UIApplication \*)app openURL:(NSURL \*)url sourceApplication:(NSString \*)source annotation:(id)annotation { if ([[DBSession sharedSession] handleOpenURL:url]) { if ([[DBSession sharedSession] isLinked]) { NSLog(@"App linked successfully!"); // At this point you can start making API calls } return YES; } // Add whatever other url handling code your app requires here return NO; } In addition, what would be considered calling in the background thread as oppose to calling in the main thread? - Chez B.11 years agoNew member | Level 1
In my app delegate method I checked to see if the session was linked and from my test the logs states that my session is linked.
if ([[DBSession sharedSession] isLinked]) {
NSLog(@"The session IS linked");
} else {
NSLog(@"The session is not linked");
}
I have checked my app console and is says that one users is connected to the app and it also says that I made one API call yesterday. However I don't see the test image that I wast trying to upload to dropbox. I am wondering if I am uploading the file incorrectly. This is my upload method
- (void)uploadToDropBox:(UIImage *)img
{
UIImage *testPic = [UIImage imageNamed:@"IMG_0005.jpg"];
NSArray *directories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,
YES);
NSString *documentDirectory = [directories firstObject];
NSString *imagePath = [documentDirectory stringByAppendingPathComponent:@"cardImage"];
NSString *destDir = @"/";
NSData *imageData = UIImagePNGRepresentation(testPic);
[imageData writeToFile:imagePath atomically: YES];
[self.restClient uploadFile:@"cardImage" toPath:destDir withParentRev:nil fromPath:imagePath];
[self sendBDayCard];
}
- Leah C.111 years agoNew member | Level 1
You may want to check that
[UIImage imageNamed:@"IMG\_0005.jpg"]exists in your project and that it is getting saved to your local filesystem correctly. Another thing to check would be that youruploadToDropBox:method is getting called at all. - Steve M.11 years ago
Dropbox Staff
Also, have you implemented the
uploadedFileanduploadFileFailedWithErrordelegates as described in https://www.dropbox.com/developers/core/start/ios#uploading?If the error delegate is called, you should be able to see exactly what failed.
- Mitchel K.111 years agoNew member | Level 1
Hello
I'm trying out the sdk using a generated access token but I keep getting an "Access token not found" error even though the token works fine in android.
Here is my case (swift):
let dropboxSession = DBSession(appKey: DB_KEY, appSecret: DB_SECRET, root: kDBRootAppFolder)
dropboxSession.updateAccessToken(DB_ACCESS_TOKEN, accessTokenSecret: DB_ACCESS_TOKEN_SECRET, forUserId: DB_USER_ID)
DBSession.setSharedSession(dropboxSession)So I'd appreciate to know what "DB_ACCESS_TOKEN_SECRET" should be since the generated token is a single string?
- Steve M.11 years ago
Dropbox Staff
Mitchel, your issue doesn't seem related to the one in this thread. Please start a new thread.
- Mitchel K.111 years agoNew member | Level 1
Alright here https://www.dropboxforum.com/hc/en-us/community/posts/204838359-Using-generated-access-token-with-the-iOS-sdk
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!