Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an option for base64 image #19

Closed
sandcforge opened this issue Apr 21, 2015 · 2 comments
Closed

add an option for base64 image #19

sandcforge opened this issue Apr 21, 2015 · 2 comments

Comments

@sandcforge
Copy link

Hi Xu,
Good contribution to cordova wechat plugin. I have used this great plugin in my meteor apps. It works gracefully.
One suggestion: current URL only supports remote webpage url or local file based url. I am wondering whether there is an possibility to add an option for the base64 image in 'getNSDataFromURL'

This small piece of code work well if I provide a base64 image by url

  • (NSData *)getNSDataFromURL:(NSString *)url
    {
    NSData *data = nil;

    if ([url hasPrefix:@"http://"] || [url hasPrefix:@"https://"])
    {
    data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
    }
    /* Added code_/
    else if ([url hasPrefix:@"data:image"]) {
    // a base 64 string
    NSURL *actualURL = [NSURL URLWithString:url];
    data = [NSData dataWithContentsOfURL:actualURL];
    }
    /_end of added code */
    else
    {
    // local file
    url = [[NSBundle mainBundle] pathForResource:[url stringByDeletingPathExtension] ofType:[url pathExtension]];
    data = [NSData dataWithContentsOfFile:url];
    }

    return data;
    }

Thanks,
Chen

@xu-li
Copy link
Owner

xu-li commented May 2, 2015

Thanks, @sandcforge .

I tested it on my phone, and it didn't work. Maybe you can send a pull request with your code.

-Xu

@zwlcoding
Copy link

base64 string like this data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD/4QBARXhpZgAATU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAGVKADAAQAAAABAAAGVAAAAA....

yes, is work . please add code to you project
thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants