imagekit-developer / imagekit-java

Java SDK for ImageKit.io API.
https://imagekit.io
16 stars 15 forks source link

ImageKit instantiation error #29

Open Hadit1993 opened 1 year ago

Hadit1993 commented 1 year ago

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?

Ox0017 commented 1 year ago

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.

Pradeep7976 commented 7 months ago

Still not fixed ?? 7 months

NoonieBao commented 7 months ago

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);
Hadit1993 commented 7 months ago

@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 commented 6 months ago

@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.