Upload implemented
This commit is contained in:
parent
ba0ba5f706
commit
1abf1a0c2a
@ -2,4 +2,22 @@
|
||||
<Bucket
|
||||
type = "1"
|
||||
version = "2.0">
|
||||
<Breakpoints>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "FMC Planner 2/DropboxV2ObjC.m"
|
||||
timestampString = "481121470.559941"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "192"
|
||||
endingLineNumber = "192"
|
||||
landmarkName = "-uploadToDropbox:"
|
||||
landmarkType = "5">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
</Breakpoints>
|
||||
</Bucket>
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
#pragma mark - File and directory methods
|
||||
|
||||
- (void)downloadFromDropbox:(NSArray *)files;
|
||||
- (void)uploadToDropbox:(NSData *)data;
|
||||
- (void)uploadToDropbox:(NSArray *)files;
|
||||
- (NSArray *)contentsOfPath:(NSString *)path;
|
||||
|
||||
#pragma mark - Other methods
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
}
|
||||
|
||||
#pragma mark - OAuth stuff
|
||||
// TODO: Alert on error
|
||||
- (BOOL)authorizeUserWithToke:(NSURL *)token completion:(void (^)(void))handler
|
||||
{
|
||||
NSScanner *scan = [NSScanner scannerWithString:token.absoluteString];
|
||||
@ -52,6 +53,7 @@
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: Alert on error
|
||||
- (void)deauthorizeUser
|
||||
{
|
||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
|
||||
@ -96,7 +98,8 @@
|
||||
* Pass nil as path for root dir
|
||||
* @return Content of directory at path or nil if error
|
||||
*/
|
||||
#warning make async
|
||||
// !!!: Cannot be asynchronous
|
||||
// TODO: Alert on error
|
||||
- (NSArray *)contentsOfPath:(NSString *)path
|
||||
{
|
||||
|
||||
@ -143,6 +146,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Alert on error
|
||||
- (void)downloadFromDropbox:(NSArray *)files
|
||||
{
|
||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
|
||||
@ -189,9 +193,55 @@
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Alert on error
|
||||
- (void)uploadToDropbox:(NSArray *)files
|
||||
{
|
||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
|
||||
request.URL =
|
||||
[NSURL URLWithString:@"https://content.dropboxapi.com/2/files/upload"];
|
||||
[request addValue:[NSString stringWithFormat:@"Bearer %@", _token]
|
||||
.precomposedStringWithCanonicalMapping
|
||||
forHTTPHeaderField:(@"Authorization")
|
||||
.precomposedStringWithCanonicalMapping];
|
||||
[request addValue:(@"application/octet-stream")
|
||||
.precomposedStringWithCanonicalMapping
|
||||
forHTTPHeaderField:(@"Content-Type")];
|
||||
request.HTTPMethod = @"POST";
|
||||
|
||||
// File Path
|
||||
for (NSString *string in files) {
|
||||
NSData *data = [NSJSONSerialization dataWithJSONObject:@{
|
||||
@"path" : [NSString stringWithFormat:@"/%@", string]
|
||||
.precomposedStringWithCanonicalMapping,
|
||||
@"mode" : @"overwrite".precomposedStringWithCanonicalMapping,
|
||||
}
|
||||
options:0
|
||||
error:nil];
|
||||
NSString *temp =
|
||||
[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
|
||||
temp =
|
||||
[temp stringByReplacingOccurrencesOfString:@"\\/" withString:@"/"];
|
||||
|
||||
[request addValue:temp.precomposedStringWithCanonicalMapping
|
||||
forHTTPHeaderField:(@"Dropbox-API-Arg")
|
||||
.precomposedStringWithCanonicalMapping];
|
||||
|
||||
request.HTTPBody = [NSData
|
||||
dataWithContentsOfFile:[SharedDeclerations savePathForFile:string]];
|
||||
|
||||
[NSURLConnection
|
||||
sendAsynchronousRequest:request
|
||||
queue:[[NSOperationQueue alloc] init]
|
||||
completionHandler:^(NSURLResponse *response, NSData *data,
|
||||
NSError *error){
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Other operations
|
||||
|
||||
#warning make async
|
||||
// !!!: Cannot be asynchronous
|
||||
// TODO: Alert on error
|
||||
- (NSDictionary *)getUserInfo
|
||||
{
|
||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
|
||||
|
||||
@ -110,7 +110,7 @@
|
||||
}
|
||||
else if ([((UILabel *)tapReg.view)
|
||||
.restorationIdentifier isEqualToString:@"LSKR5"]) {
|
||||
#warning EXPORT TO PMDG GOES HERE
|
||||
// TODO: Export to PMDG route format
|
||||
}
|
||||
else if ([((UILabel *)tapReg.view)
|
||||
.restorationIdentifier isEqualToString:@"LSKR6"]) {
|
||||
|
||||
@ -94,12 +94,7 @@
|
||||
DropboxV2ObjC *dbClient =
|
||||
((AppDelegate *)[UIApplication sharedApplication].delegate).dbClient;
|
||||
NSLog(@"%@", [dbClient contentsOfPath:nil]);
|
||||
[dbClient downloadFromDropbox:@[
|
||||
@"lol.txt",
|
||||
@"rofl.txt",
|
||||
@"tldr.txt",
|
||||
@"lol Kopie 3.txt"
|
||||
]];
|
||||
[dbClient uploadToDropbox:@[ @"EDDFEDDM001" ]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user