-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File partially uploading #14
Comments
I need more information. How large are your files? Have you tried using the demo program to upload/download files using the simulator? When you say "only a small portion" how small is small? The simulator is really perfect for testing scenarios such as these. I would be interested to know how much gets transferred, if you ever get a failure, etc. Setting breakpoints on the callbacks can be invaluable. Sorry I was unable to reply immediately, I have a fire of my own that has to be tended to. Cheers, Lloyd On Mar 19, 2013, at 21:13 , Andrew notifications@github.com wrote:
|
My files are usually plain text files (HTML, CSS, etc) as well as some image files (PNG, JPG, etc) ranging from 4 kilobytes to 4 megabytes. The user specifies the files, but I am going to keep the maximum size 5mb. When I try to upload an image that is 68kb in size, it cuts off the image and less than half of it is there. Here is my code (everything seems to work fine except for my current issue) -(void)uploadFile
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *theFile = [documentsDirectory stringByAppendingPathComponent:currentFileName];
uploadedfilename = filefield.text;
NSLog(@"Uploading...");
uploadData = [NSData dataWithContentsOfFile:theFile];
uploadRequest = [BRRequestUpload initWithDelegate:self];
uploadRequest.hostname = @"123.456";
uploadRequest.username = @"myusername";
uploadRequest.password = @"12345";
uploadRequest.path = [NSString stringWithFormat:@"/%@/%@",dirfield.text,uploadedfilename];
[uploadRequest start];
}
- (void) percentCompleted: (BRRequest *) request
{
NSLog(@"%f completed...", request.percentCompleted);
NSLog(@"%ld bytes this iteration", request.bytesSent);
NSLog(@"%ld total bytes", request.totalBytesSent);
}
- (long) requestDataSendSize: (BRRequestUpload *) request
{
return [uploadData length];
}
- (NSData *) requestDataToSend: (BRRequestUpload *) request
{
NSData *temp = uploadData;
uploadData = nil;
return temp;
}
-(BOOL) shouldOverwriteFileWithRequest: (BRRequest *) request
{
if (request == uploadRequest)
{
return YES;
}
return NO;
}
-(void) requestCompleted: (BRRequest *) request
{
if (request == uploadRequest)
{
NSLog(@"%@ completed!", request);
filelabel.text = @"Upload Complete";
uploadRequest = nil;
}
if (request == createDir)
{
NSLog(@"%@ createdir completed!", request);
createDir = nil;
}
}
-(void) requestFailed:(BRRequest *) request{
if (request == uploadRequest)
{
NSLog(@"Fail: %@", request.error.message);
uploadRequest = nil;
}
if (request == createDir)
{
NSLog(@"DirCreate Fail: %@", request.error.message);
createDir = nil;
}
} |
I really should put this as a message in github: you are attempting to read the ENTIRE file into memory. That's a no-no as it doesn't appear to work (I say appear because this was an issue with another user). What you SHOULD do is instead open the file and read it in bits at at time. That's what requestDataToSend:request is for. You open the file in uploadFile: and then everytime you get a requestDataToSend:request you create an NSData object with a bit of the file. This was done specifically to satisfy large data transfers. Let me know if this doesn't answer your question. The other user had the same problem which is why I modified the code. Cheers, Lloyd On Mar 21, 2013, at 20:31 , Andrew notifications@github.com wrote:
|
I got it working! Thanks for all of your help. |
Excellent! Glad I could be of some help! On Mar 22, 2013, at 15:11 , Andrew notifications@github.com wrote:
|
AASoftware, would you mind sharing how you got it to work? |
Hello,
I have noticed with BlackRaccoon that my files are being uploaded, but not the entire file. Images show up as empty with only a small portion of the image uploaded, and even large HTML files are being cut off. I have followed the instructions in the Readme/wiki. How could I fix this?
The text was updated successfully, but these errors were encountered: