Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
I am working on a little app to upload files to my server and wow what a pain it is compared to downloading them. I have an NSOpenPanel that allows me to select a file. In this case I am just picking a .jpg file to test. My setDidFinishSelector gets called and said logged in, but when I check my server the file is not there. I changed the user/pass in the code I posted but it seems to log in fine. But it fails to upload a file? Can anyone see the problem off hand?

Code:
-(IBAction)addFileButton:(id)sender{
    NSOpenPanel *savePath = [NSOpenPanel openPanel];
    [savePath setCanChooseFiles:YES];
    [savePath setCanChooseDirectories:YES];
    NSInteger result = [savePath runModal];
    NSString *stringFromIndex;
    
    if (result == NSCancelButton) {
        [savePath orderOut:self];
    }
    
    if ( result == NSOKButton) {

        NSString *tempString = [[NSString alloc] initWithString:[[savePath URL]absoluteString]];
        NSArray *cutString = [tempString componentsSeparatedByString:@"file://localhost"];
        stringFromIndex = [cutString objectAtIndex:1];
        
        NSData *dataToUpload = [[NSData alloc] initWithContentsOfFile:stringFromIndex];
        
        NSURL *url = [NSURL URLWithString:@"http://user:pass@website/uploads/"];
    
        request = [[ASIFormDataRequest alloc] initWithURL:url];

        [request addData:dataToUpload forKey:@"file"];
        
        [request setDelegate: self];
        [request setDidFailSelector: @selector(loginRequestFailed)];
        [request setDidFinishSelector: @selector(loginRequestFinished)];
        
        [request startAsynchronous];
    }
    
}
-(void)loginRequestFinished{
    NSLog(@"Loged in");
}

-(void)loginRequestFailed{
    NSLog(@"failed");
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.