-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathPWWebRequestFileFormData.m
More file actions
56 lines (39 loc) · 1.25 KB
/
PWWebRequestFileFormData.m
File metadata and controls
56 lines (39 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// ProWidgets
//
// 1.0.0
//
// Created by Alan Yip on 18 Jan 2014
// Copyright 2014 Alan Yip. All rights reserved.
//
#import "PWWebRequestFileFormData.h"
@implementation PWWebRequestFileFormData
+ (instancetype)createWithFilename:(NSString *)filename contentType:(NSString *)contentType inBundle:(NSBundle *)bundle {
PWWebRequestFileFormData *instance = [self new];
instance.path = [NSString stringWithFormat:@"%@/%@", [bundle bundlePath], filename];
instance.filename = filename;
instance.contentType = contentType;
return [instance autorelease];
}
+ (instancetype)createWithPath:(NSString *)path contentType:(NSString *)contentType {
PWWebRequestFileFormData *instance = [self new];
instance.path = path;
instance.filename = [path lastPathComponent];
instance.contentType = contentType;
return [instance autorelease];
}
- (NSData *)readData {
if (![[NSFileManager defaultManager] fileExistsAtPath:_path]) {
LOG(@"PWWebRequestFileFormData: File does not exist at '%@'.", _path);
return nil;
}
return [[NSFileManager defaultManager] contentsAtPath:_path];
}
- (void)dealloc {
DEALLOCLOG;
[_path release], _path = nil;
[_filename release], _filename = nil;
[_contentType release], _contentType = nil;
[super dealloc];
}
@end