将大文件(大于50MB)上载到FTP服务器

时间:2014-11-11 00:46:16

标签: ios objective-c ftp

我目前正在iOS应用中使用Black Raccoon库,使用以下建议代码将小文件上传到FTP服务器:

- (IBAction) uploadFile :(id)sender {
//----- get the file path for the item we want to upload
NSString *applicationDocumentsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filepath = [NSString stringWithFormat: @"%@/%@", applicationDocumentsDir, @"file.text"];

//----- read the entire file into memory (small files only)
uploadData = [NSData dataWithContentsOfFile: filepath];

//----- create our upload object
uploadFile = [[BRRequestUpload alloc] initWithDelegate: self];

//----- for anonymous login just leave the username and password nil 
uploadFile.path = @"/home/user/myfile.txt";     
uploadFile.hostname = @"192.168.1.100";
uploadFile.username = @"yourusername";
uploadFile.password = @"yourpassword";

//----- we start the request
[uploadFile start]; }


- (NSData *) requestDataToSend: (BRRequestUpload *) request {
//----- returns data object or nil when complete
//----- basically, first time we return the pointer to the NSData.
//----- and BR will upload the data.
//----- Second time we return nil which means no more data to send
NSData *temp = uploadData;   // this is a shallow copy of the pointer

uploadData = nil;            // next time around, return nil...

return temp; }

上传大文件(大于50MB)需要做什么,而无需将整个文件写入内存?

0 个答案:

没有答案