lloydsargent / BlackRaccoon

IOS FTP Client Code
102 stars 37 forks source link

Image uploads halfway #9

Closed canzhiye closed 11 years ago

canzhiye commented 12 years ago

I'm uploading images through FTP, and the image only uploads halfway sometimes. The rest of the picture is just a gray bar. Any help would be appreciated.

lloydsargent commented 12 years ago

How large are your images? Do you have any problems with conventional FTP? Do you get any error codes? I need more information in order to assist you.

canzhiye commented 12 years ago

They are images taken with an iPod Touch or iPhone, so around 2-5MB usually. The code runs through the "request completed" part. I didn't get any error codes, and the weird thing is, it only happens occasionally. I don't have any problems with conventional FTP.

canzhiye commented 12 years ago

and thank you for your prompt reply

lloydsargent commented 12 years ago

Ok, you have a sporadic error.

This is either in Apple's code, BlackRaccoon, or your code. Unfortunately, since I don't have access to your code or your server or your device, you're going to have to do the bulk of the debugging.

First, I would attempt to determine if it fails the same number of bytes. If so, it is possible there is coding error.

Second, I would look to see if the ftp server has any log messages. Particularly if it closed out ports for some reason.

Third, pepper your code with debug messages and run in the simulator. Check to make sure you are not accidentally sending nil due to a coding error.

Fourth, check that you aren't accidentally closing out the upload due to a timeout.

BR is pretty simple when uploading data and only will upload what you tell it. If you close everything out or send nil when it isn't done, it will obediently follow your directions.

Good luck and let me know what you find.

canzhiye commented 12 years ago

Will do! I'll let you know!

canzhiye commented 11 years ago

Just to follow up: If I put a breakpoint in the requestDataToSend method, everything goes fine. However, if I remove breakpoints, only 5.5MB of my 5.6MB file is uploaded! It's weird stuff...

canzhiye commented 11 years ago

I found a really awkward workaround. But it works. I cancel the request using [request cancelRequest] once request.percentCompleted = 1.25 (or some number greater than 1)

lloydsargent commented 11 years ago

Sounds like a timing issue. I would run it under the simulator and look for an excessive number of retries.

My test program uses "image.jpg" as a file to upload, you my want to try it under the simulator as a sanity test and see if you still have problems.

lloydsargent commented 11 years ago

This is very odd... request.percentCompleted should never be larger than 1.0 if you are using the requestDataSendSize:request method.

canzhiye commented 11 years ago

I modified the requestDataSendSize:request method. If I leave it as is, the picture doesn't upload all the way. I'll give it a shot in the simulator.

lloydsargent commented 11 years ago

Are you loading the ENTIRE file into NSData? requestDataToSend was written so that you can "chunkify" a large file - this allows for sending large files. Loading 5 MB into NSData may be problematic (I personally have not tested files this large).

The idea is that you would read a small section of the file you want to send (say, 10-20K' worth) and return it in an NSData object.

5 MB doesn't seem like it should be causing problems, but then I don't know what you are also running.