0
votes

I am using Dropbox sync api for downloading text file and upload video file from/to dropbox via my ios application.

I am struggling while uploading heavy video file.While i am uploading video file of duration 15 to 20 minutes its uploaded correctly, but if the duration is more than 25 minutes then it gets memory waring and app crashes.

I am using this code on upload button action

DBPath *paths=[[DBPath root] childPath:[self.allVideoArray objectAtIndex:Selectedvideo]];
DBFile *createfile=[filesystem createFile:paths error:nil];
NSData  *data=[[NSData alloc]initWithContentsOfFile:self.path];
[createfile writeData:data error:nil];     
[data relese];

Please some body way me out from this problem. Any help should be appreciable, Thanks in advance.

1
Sync API seems to not allow video upload for me. It says file type not allowed. how did you get it working with the Sync api? - Siriss

1 Answers

1
votes

The problem is that you create an NSData instance containing the entire file. If the file is too big to fit into memory your app will crash. There are better ways to write large files to a DBFile.

Since you have a path to the local file you could do:

DBPath *paths=[[DBPath root] childPath:[self.allVideoArray objectAtIndex:Selectedvideo]];
DBFile *createfile=[filesystem createFile:paths error:nil];
[createFile writeContentsOfFile:self.path shouldSteal:NO error:nil];

Another option would be to read the file at self.path in smaller chunks and use DBFile appendData:error:.

Side note - you really need to check return values to make sure these calls are working or not and make use of the error parameter to log the cause of the problem (if any).