(Java) Download Image (JPG, GIF, etc.) to Base64
Demonstrates how to download an image, or any type of file, to get the data in base64 encoding format.
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttp http = new CkHttp();
CkBinData bd = new CkBinData();
boolean success = http.DownloadBd("https://www.chilkatsoft.com/images/starfish.jpg",bd);
if (success == false) {
System.out.println(http.lastErrorText());
return;
}
String base64_image_data = bd.getEncoded("base64");
System.out.println("image data in base64 format:");
System.out.println(base64_image_data);
}
}
|