How to remove the path from an attachment when calling addAttachmentData?
Asked Answered
C

1

1

When adding an attachment to an email, the file name gets it's complete path.

For a file located in:

/var/mobile/Applications/C3BBAA5F-07FE-4E26-9661-CB492E06BD2E/Documents/

I'm getting as a result, a file named:

_var_mobile_Applications_C3BBAA5F-07FE-4E26-9661-CB492E06BD2E_Documents_Clock.sqlite

When I need my filename to be:

Clock.sqlite

Here's my code:

NSString *path = [self getDatabaseFilePath];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"application/x-sqlite3" fileName:path];

How can I get the attachment to have only the filename and extension, without the complete path?

Thank you!

Cabbage answered 17/8, 2013 at 8:27 Comment(0)
G
2

This should do what you want:

NSString *path = [self getDatabaseFilePath];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"application/x-sqlite3" fileName:[path lastPathComponent]];
Gentlemanfarmer answered 17/8, 2013 at 8:32 Comment(1)
You were 4 seconds behind me, but you had the same correct idea... so +1 to you!Bilestone

© 2022 - 2024 — McMap. All rights reserved.