Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Sources/Core/DAVRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,15 @@
@property (copy) NSString *dataMIMEType; // defaults to application/octet-stream

@end

@interface DAVPutStreamRequest : DAVRequest {
@private
NSString *_pfilepath;
NSString *_MIMEtype;
}

// Pass - Path to local file
@property (strong) NSString *filepath;
@property (copy) NSString *dataMIMEType; // defaults to application/octet-stream

@end
36 changes: 36 additions & 0 deletions Sources/Core/DAVRequests.m
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,39 @@ - (NSURLRequest *)request {
}

@end

@implementation DAVPutStreamRequest

- (id)initWithPath:(NSString *)aPath {
if ((self = [super initWithPath:aPath])) {
self.dataMIMEType = @"application/octet-stream";
}
return self;
}

@synthesize filepath = _pfilepath;
@synthesize dataMIMEType = _MIMEType;

- (NSInputStream *)connection:(NSURLConnection *)connection needNewBodyStream:(NSURLRequest *)req {

return [NSInputStream inputStreamWithFileAtPath:_pfilepath];
}

- (NSURLRequest *)request {
NSParameterAssert(_pfilepath != nil);

NSError *error = nil;
NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:_pfilepath
error:&error];
if (!attrs) return nil;

NSString *len = [NSString stringWithFormat:@"%lld", attrs.fileSize];
NSMutableURLRequest *req = [self newRequestWithPath:self.path method:@"PUT"];
[req setValue:[self dataMIMEType] forHTTPHeaderField:@"Content-Type"];
[req setValue:len forHTTPHeaderField:@"Content-Length"];
[req setHTTPBodyStream:[NSInputStream inputStreamWithFileAtPath:_pfilepath]];

return req;
}

@end