ImageKit instantiation error
Hi. I went along with documentaion and added config.properties in my resource folder and added public and private keys and url endpont there. and here is my imagekit instantiation:
@SpringBootApplication
class EShopBackApplication
fun main(args: Array<String>) {
runApplication<EShopBackApplication>(*args)
val imageKit = ImageKit.getInstance()
val config = Utils.getSystemConfig(EShopBackApplication::class.java)
imageKit.config = config
}
When I run the app I got this error:
Exception in thread "main" java.lang.NoSuchFieldError: Companion
at okhttp3.internal.Util.<clinit>(Util.kt:70)
at okhttp3.OkHttpClient.<clinit>(OkHttpClient.kt:1073)
at io.imagekit.sdk.tasks.RestClient.<init>(RestClient.java:60)
at io.imagekit.sdk.ImageKit.getInstance(ImageKit.java:40)
at com.hadit1993.eshopback.EShopBackApplicationKt.main(EShopBackApplication.kt:16)
What is the problem?
Problem is the required dependency com.squareup.okhttp3:okhttp:3.10.0 (from 2018)
You are probably using a newer okhttp version in your project through spring.
Still not fixed ?? 7 months
problem still......however, as 0x00117 say, i add the okhttp dependency, now it work well.
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.10.0</version>
</dependency>
ImageKit imageKit = ImageKit.getInstance();
Configuration config = new Configuration(your_public_key, your_private_key, your_url_endpoint);
imageKit.setConfig(config);
byte[] bytes1 = file.getBytes();
FileCreateRequest fileCreateRequest = new FileCreateRequest(
bytes1, // required, "binary", "base64" or "file url"
"sample-image11.jpg" // required
);
Result resultt = imageKit.upload(fileCreateRequest);
System.out.println(resultt);
@NoonieBao I recommend you not using this library in real projects. it's obvious that this repository is not maintained properly and in the future you may get dependency version conflict errors.
@NoonieBao I recommend you not using this library in real projects. it's obvious that this repository is not maintained properly and in the future you may get dependency version conflict errors.
Good tips, thanks! It is only being used for my personal project, and I have made a backup for unexpected conflicts.