Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
[email protected] web/email now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!

Paste

Pasted as Plain Text by mohan ( 12 years ago )
-(IBAction)clickFileuploadbtn:(id)sender;
{
    NSLog(@"2");
    picker1 =
    [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];
    
    picker1.delegate      = self;
    picker1.allowsPickingMultipleItems = YES;
    picker1.prompt      = NSLocalizedString (@"Add songs to play", "Prompt in media item picker");
    
    // The media item picker uses the default UI style, so it needs a default-style
    //  status bar to match it visually
    [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleDefault animated: YES];
    
    [self presentModalViewController: picker1 animated: YES];
    [picker1 release];
    // [Uploads FileUpload];
}
- (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection
{


    [self dismissModalViewControllerAnimated: YES];
    
    NSLog(@"%@ %d",mediaItemCollection,mediaItemCollection.count);
    
    NSArray *newMediaItem= [mediaItemCollection items];
    
    
    MPMediaItem *item=[[newMediaItem objectAtIndex:0] retain];
    
    [self uploadMusicFile:item];
}
- (void)mediaPickerDidCancel:(MPMediaPickerController *)mediaPicker
{
    [self dismissModalViewControllerAnimated: YES];

    NSLog(@"cancel");
    
}


- (void) uploadMusicFile:(MPMediaItem *)song
{
    NSURL *url = [song valueForProperty: MPMediaItemPropertyAssetURL];
    
    // Given some file path URL: NSURL *pathURL
    // Note: [pathURL isFileURL] must return YES
    NSString *path = [NSString stringWithFormat:@"%@",url];
    NSLog(@"path %@",path);
    NSData *data = [[NSFileManager defaultManager] contentsAtPath:path];
    NSLog(@"data %@" ,data);
    NSString *audioName = @"myAudio.caf";
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://192.168.1.176:1001/api?type=iphoneupload"]];
    [request addData:data withFileName:audioName andContentType:@"audio/caf" forKey:@"audioFile"];
    [request setDelegate:self];
    [request setTimeOutSeconds:500];
    [request setDidFinishSelector:@selector(uploadRequestFinished:)];
    [request setDidFailSelector:@selector(uploadRequestFailed:)];
    [request startAsynchronous];

    

}

- (void)uploadRequestFinished:(ASIHTTPRequest *)request
{
    UIApplication* app = [UIApplication sharedApplication];
    app.networkActivityIndicatorVisible = NO;
    NSData *webData = [[NSData alloc] initWithData:[request responseData]];
    NSString *strEr =  [[NSString alloc] initWithData:webData encoding:NSUTF8StringEncoding];
    NSLog(@"strEr %@",strEr);
}

- (void) uploadRequestFailed:(ASIHTTPRequest *)request
{
    NSLog(@"responseStatusCode %i",[request responseStatusCode]);
    NSLog(@"responseString %@",[request responseString]);
    NSError *error = [request error];
    NSLog(@"error %@",error);
    UIApplication* app = [UIApplication sharedApplication];
    app.networkActivityIndicatorVisible = NO;
}

 

Revise this Paste

Your Name: Code Language: