diff options
| author | Teddy Wing | 2012-04-26 01:48:48 -0400 |
|---|---|---|
| committer | Teddy Wing | 2012-04-26 01:50:12 -0400 |
| commit | b2ce2ee890be7020ac0b09fe490fe2ee72fd80a9 (patch) | |
| tree | 6f0df340393aa4ede34c2f12b3141e8c80affde9 | |
| parent | 7d43320232db0aca9332d841e2233d737a80a74e (diff) | |
| download | Video-Tuneup-b2ce2ee890be7020ac0b09fe490fe2ee72fd80a9.tar.bz2 | |
WebserviceCommunicator correctly receives a file and writes it to the tmp directory.
| -rw-r--r-- | Video Tuneup/Classes/WebserviceCommunicator.h | 2 | ||||
| -rw-r--r-- | Video Tuneup/Classes/WebserviceCommunicator.m | 21 |
2 files changed, 21 insertions, 2 deletions
diff --git a/Video Tuneup/Classes/WebserviceCommunicator.h b/Video Tuneup/Classes/WebserviceCommunicator.h index faaa55a..5c0a378 100644 --- a/Video Tuneup/Classes/WebserviceCommunicator.h +++ b/Video Tuneup/Classes/WebserviceCommunicator.h @@ -10,6 +10,8 @@ @interface WebserviceCommunicator : NSObject <NSURLConnectionDelegate> +@property (nonatomic, retain) NSFileHandle *fileHandle; + -(void)mixMusic:(NSURL *)file; @end diff --git a/Video Tuneup/Classes/WebserviceCommunicator.m b/Video Tuneup/Classes/WebserviceCommunicator.m index d53ee90..bffd7ac 100644 --- a/Video Tuneup/Classes/WebserviceCommunicator.m +++ b/Video Tuneup/Classes/WebserviceCommunicator.m @@ -12,6 +12,18 @@ @implementation WebserviceCommunicator +@synthesize fileHandle; + +- (id)init { + self = [super init]; + if (self) { + NSString *songPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"mixed_song.mp3"]; + [[NSFileManager defaultManager] createFileAtPath:songPath contents:nil attributes:nil]; + fileHandle = [NSFileHandle fileHandleForWritingAtPath:songPath]; + } + return self; +} + -(void)mixMusic:(NSURL *)file { NSString *uploadFileName = [file lastPathComponent]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/blend/%@", BASEPATH, uploadFileName]] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:130.0]; // BASEPATH/blend/:filename @@ -22,8 +34,9 @@ NSData *songData = [NSData dataWithContentsOfURL:file]; NSMutableData *requestData = [[NSMutableData alloc] init]; - //[requestData appendData:[NSData dataWithBytes:[song length:<#(NSUInteger)#> +// To send extra params: +// // for (NSString *paramName in params) ... // [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; // [body appendData:[@"Content-Disposition: form-data; name=\"photo-description\"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; @@ -47,7 +60,9 @@ -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { NSLog(@"Got response data"); - NSLog(@"Data was: %@", [NSString stringWithUTF8String:[data bytes]]); + + [fileHandle seekToEndOfFile]; + [fileHandle writeData:data]; } -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { @@ -56,6 +71,8 @@ -(void)connectionDidFinishLoading:(NSURLConnection *)connection { NSLog(@"Song send finished loading."); + + [fileHandle closeFile]; } @end |
