I am attempting to upload an image to my server in java and then download it in iOS within an app. When I upload / download with java, it works, but when I download it in iOS the image just turns up black. Also, when I view the image in browser it has a purple hue over it convincing me that the image is corrupt. Am I not uploading the image correctly?
Code:
public void uploadToServer() {
String server = "ip";
int port = 21;
String user = "name";
String pass = "pass";
FTPClient ftpClient = new FTPClient();
try {
ftpClient.connect(server, port);
ftpClient.login(user, pass);
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ByteArrayOutputStream os = new ByteArrayOutputStream();
int w = 765;
int h = 503;
double d = .85;
BufferedImage img = resize(client.methods.getClientImage(),
(int) (w * d), (int) (h * d));
ImageIO.write(img, "JPG", os);
InputStream inputStream = new ByteArrayInputStream(os.toByteArray());
String secondRemoteFile = "directory";
// System.out.println("Start uploading file");
OutputStream outputStream = ftpClient
.storeFileStream(secondRemoteFile);
byte[] bytesIn = new byte[4096];
int read = 0;
while ((read = inputStream.read(bytesIn)) != -1) {
outputStream.write(bytesIn, 0, read);
}
inputStream.close();
outputStream.close();
ftpClient.completePendingCommand();
} catch (IOException ex) {
System.out.println("Error: " + ex.getMessage());
ex.printStackTrace();
} finally {
try {
if (ftpClient.isConnected()) {
ftpClient.logout();
ftpClient.disconnect();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
Heres the purple tint:
iOS Code:
- (void) refreshImage {
client.image = [UIImage imageWithData:[NSData dataWithContentsOfURL: [NSURL URLWithString:@"http://link.jpg"]]]; ;
}