Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to upload image in Specific folder of your application iOS

    • 0
    • 3
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 696
    Comment on it

    Here is the code for UIImagePickerController Delegate. In this Code when we select an image from UIImagePickerController then we call this delegate function which upload the selected image to your local application folder. You have to first find the path of folder from documents directory and then save the image to that specific folder.

    There is one more thing that if you are uploading multiple images then the name of image should be dynamic otherwise next image will replace the previous image in that folder.

    - (void)imagePickerController:(UIImagePickerController *)picker
    didFinishPickingMediaWithInfo:(NSDictionary *)info {
    
    UIImage* image;
    
            if([[info valueForKey:@"UIImagePickerControllerMediaType"] isEqualToString:@"public.image"])
            {
                image = [info valueForKey:@"UIImagePickerControllerOriginalImage"];
    
                NSString *stringPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]stringByAppendingPathComponent:@"DispayImages"];
                //DislayImages is your folder name
                NSError *error = nil;
    
                if (![[NSFileManager defaultManager] fileExistsAtPath:stringPath])
                    [[NSFileManager defaultManager] createDirectoryAtPath:stringPath withIntermediateDirectories:NO attributes:nil error:&error];
    
                NSString *fileName = [stringPath stringByAppendingFormat:@"/imageName.jpg"];
                personImageUrl=fileName;
                [profileImageData writeToFile:fileName atomically:YES]; //upload file to folder path
    
                NSData *imageData = UIImagePNGRepresentation([UIImage imageWithContentsOfFile:fileName]);
                profileImageData = UIImageJPEGRepresentation(image, 1.0);
    
               NSString  *imgBase64String= [imageData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithCarriageReturn]; //convert image into base64 string
            }
        }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: