1

I need some help. I am trying to attach files to mail using, [mail addAttachmentData:attachmentData mimeType:@"image/png" fileName:fileName]; but the problem is that if i need to send a .jpeg image i need to repeat code just for setting mime type to "mimeType:@"image/jpeg". My question is that is there any general mimeType that can attach any kind of file irrespective of .doc,.ppt,.pdf or an audio or video file. is there any general mimeType: for an kind of attachment.

Thanks in advance.

iSagar
  • 107
  • 1
  • 11

3 Answers3

1

Maybe you could use @"application/octet-stream", which means something like “Binary data file”

José Manuel Sánchez
  • 5,215
  • 2
  • 31
  • 24
1

Possible solution (taken from here):

NSString* fileMIMEType(NSString * file) {
    CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (CFStringRef)[file pathExtension], NULL);
    CFStringRef MIMEType = UTTypeCopyPreferredTagWithClass (UTI, kUTTagClassMIMEType);
    CFRelease(UTI);
    return [(NSString *)MIMEType autorelease];
}

You need to include the MobileCoreServices framework, and add:

#import <MobileCoreServices/MobileCoreServices.h>

Another possible solution is an open source project MagicKit.

Community
  • 1
  • 1
Michael Kessler
  • 14,245
  • 13
  • 50
  • 64
0
NSURL * fileURL1 = [[NSURL alloc] initFileURLWithPath:videoStr];
NSData *videofile = [[NSData alloc] initWithContentsOfURL:fileURL1];
[picker addAttachmentData:videofile mimeType:@"video/quicktime" fileName:@"Video.mov"];

It will work fine for attaching video file in mfmai

atxe
  • 5,029
  • 2
  • 36
  • 50
Prasad.Jakka
  • 159
  • 2
  • 8