SparkFun Forums 

Where electronics enthusiasts find answers.

Tips and questions relating to the GPS modules from SFE
By DannyDJ
Hi! I would like to send picture to FTP server and i managed to send it but it gets very corrupted. In picture are missing segment of picture. Picture in module is saved correctly but when i try to send it, half of picture is good but another half is corrupted. For reading picture i'm using file.readlines()?

Any ideas?
By jasonharper
readlines() is completely inappropriate for use with a picture, as it breaks up the file into lines of text - even though carriage return/linefeed characters do not have any such meaning in most graphics formats. Use if you're sure the entire file will fit into RAM; otherwise, use something like in a loop to read it in chunks. Also, use mode "rb" instead of "r" when opening the file - I'm not sure if that's absolutely required on the Telit modules, but it won't hurt to explicitly indicate that you're reading a binary file rather than text.
By DannyDJ
Hi! Tnx for the reply!I've try before the in a loop like:

for line

but then data is sent "bit by bit" until it reaches the 4096 and it is to slow for my project, for 4096 size of data takes about 2 minutes to send to FTP server.I'm using always 'rb' = read binary
Pictures stored in module are about 40kb.
By jasonharper
That's not valid syntax; I assume you meant "for line in", which I'd expect to be horribly slow! The read method returns a single string, not a list of strings as readlines does; iterating over a string gives you characters, not lines, so you're sending a single character at a time (and NOT looping to read additional blocks of data from the file). Try something like this:
Code: Select all
while 1:
    block =
    if not block: 
        break    # EOF reached
By DannyDJ
Hi! Tnx again.I'll try your way. I'll post the results.
By DannyDJ
Finally fixed it!The problem was that while sending binary data of picture the data was lost during upload, so you have to check for the lost data and resend again binary data which was lost.
And this works for readlines() and read(size).
By gussy
What are you using to take the picture if you don't mind me asking?
By DannyDJ
I take picture from IP camera.