commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Griffiths <dgriffi...@boats.com>
Subject Another corrupt image issue...
Date Wed, 09 Nov 2005 02:25:13 GMT
I'm new to the commons-net library, but I've read through the FAQ and 
the APIs. I've also googled my problem.

I'm downloading images from a site using the commons-HttpClient, 
resizing them, and then ftp'ing them up to an image server, but the 
images appear to be corrupt (can't view them in a browser on the server 
they've been uploaded to, ditto if I scp them down).

I am setting the file-transfer-type to binary when I create the connection:

                
ftpConnections[iServerCount].setFileTransferMode(FTPClient.BINARY_FILE_TYPE);
                ftpConnections[iServerCount].completePendingCommand();

I've tried various things to fix this.

Attempt #1:

Handing a stream over to the FTPClient to upload the image
FileInputStream fInputStream = null;

    fInputStream = new FileInputStream(f);
    ftpConnections[iServerCount].changeWorkingDirectory(strRemoteDirectory);
    ftpConnections[iServerCount].setFileTransferMode(FTP.BINARY_FILE_TYPE);
    ftpConnections[iServerCount].completePendingCommand();
    if ( ftpConnections[iServerCount].storeFile(f.getName(), 
fInputStream) ) bOneSucceeded = true;

Attempt #2

Using two streams to upload the image

    fInputStream = new FileInputStream(f);
    ftpConnections[iServerCount].changeWorkingDirectory(strRemoteDirectory);
    ftpConnections[iServerCount].setFileTransferMode(FTP.BINARY_FILE_TYPE);
    ftpConnections[iServerCount].completePendingCommand();

    OutputStream os = 
ftpConnections[iServerCount].storeFileStream(f.getName());
    byte[] bData = new byte[2048];
    while(true)
    {
        int iBytesRead = fInputStream.read(bData);
        if (iBytesRead == -1) break;
        os.write(bData, 0, iBytesRead);
    }
    os.flush();
    os.close();
    fInputStream.close();
    ftpConnections[iServerCount].completePendingCommand();

I get a successful status back in both cases.

I've checked that the images I am downloading are fine and processing 
are fine (the images I am ftp'ing up are fine). I've also tried using a 
DataInputStream instead of a FileInputStream.

I've also tried using the FTP.IMAGE_FILE_TYPE to see if that would make 
a difference.

Any insight would be appreciated.

David

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message