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

Wrong attachment path #14

Closed
oabad opened this issue Feb 18, 2014 · 4 comments
Closed

Wrong attachment path #14

oabad opened this issue Feb 18, 2014 · 4 comments
Assignees

Comments

@oabad
Copy link

oabad commented Feb 18, 2014

Hi.

I'm testing this pugin with Phonegap Build.

All works fine but I can't attach an image.

I'm using the camera to capture image and send email composer the URI of image.

The path is like: file:///var/mobile/Applications/......../tmp/cdv_photo_001.jpg

I tried to slice the firsts character but doesn't work.

How can I attach image to email?

Thanks.

@katzer
Copy link
Owner

katzer commented Feb 19, 2014

I think the issue is the path. Its a path on your Mac and not of your Phone.
If you use the cordova camera plugin it will tell you an image URI. And as far as I think you have to cut of the "file://localhost/" at the beginning.

@oabad
Copy link
Author

oabad commented Feb 19, 2014

Hi, katzer and thanks for your response.

The path "file:///var/mobile/Applications/......../tmp/cdv_photo_001.jpg" is the URI path of my iphone.

I tried to cut path like "var/mobile...........jpg" but doesn't work.

I don't know what path pass to plugin.

Do you have any example of this?

Thanks and regards.

@bau720123
Copy link

+1

@katzer
Copy link
Owner

katzer commented Mar 1, 2014

Servus,

you have to use the absolute path. For example

"/Users/sebastian/Library/Application Support/iPhone Simulator/7.0.3/Applications/E7981856-801F-4355-8687-EAACDF8B2A54/HelloCordova.app/../Documents/image.jpg"

But thats not very handy. I want to change that with the next release.

For iOS you can replace the method setAttachments: with the following code:

- (void) setAttachments:(NSArray*)attatchments ofDraft:(MFMailComposeViewController*)draft
{
    if (attatchments)
    {
        NSString* bundlePath = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/"];

        for (NSString* path in attatchments)
        {
            NSString* fullPath = [bundlePath stringByAppendingString:path];
            NSData* data       = [[NSFileManager defaultManager] contentsAtPath:fullPath];

            NSString* pathExt  = [path pathExtension];
            NSString* fileName = [path pathComponents].lastObject;
            NSString* mimeType = [self getMimeTypeFromFileExtension:pathExt];

            [draft addAttachmentData:data mimeType:mimeType fileName:fileName];
        }
    }
}

Then you can specify your attachments with an relative path.

attachments: ['../tmp/cdv_photo_001.jpg']

@katzer katzer self-assigned this Mar 1, 2014
@katzer katzer closed this as completed Mar 1, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants