AdeMike's avatar

Laravel ImageKit.io error

I tried uploading my image to imageKit.io platform, it successfully upload but its a broken image and if you get the url , it always show 404. my code below

$imageKit = new ImageKit(
            "public_URL",
            "private_URL",
            "image.io_URL"
        );

        // For File Upload
        $uploadFile = $imageKit->uploadFile([
            'file' => $request->file('image'),
            'fileName' => 'new-file'
        ]);
        ddd($uploadFile);

After i upload it, i get the response below with a fileType showing non-image

ImageKit\Utils\Response {#1308 ▼
  +err: null
  +success: {#1331 ▼
    +"fileId": "62c2c202afc5d35c08010892"
    +"name": "new-file_TxaO4DK_Q"
    +"size": 14
    +"versionInfo": {#1329 ▶}
    +"filePath": "/new-file_TxaO4DK_Q"
    +"url": "https://ik.imagekit.io/ycwiiy2r8a/new-file_TxaO4DK_Q"
    +"fileType": "non-image"
    +"AITags": null
  }
}

How do i get the image to display properly, if i copy the url to browser, it shows 404, if i check the platform dashboard, it gets uploaded as a broken image file

0 likes
5 replies
Sinnbeck's avatar

Are you sure it's an image file? Use laravel validation to ensure it's a file and an image

AdeMike's avatar


use ImageKit\ImageKit;

 public function uploadImageTestPost(Request $request)
    {
        $request->validate([
            'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
        ]);
         $imageKit = new ImageKit(
            "public_URL",
            "private_URL",
            "image.io_URL"
        );

        // For File Upload
        $uploadFile = $imageKit->uploadFile([
            'file' => $request->file('image'),
            'fileName' => 'new-file'
        ]);
        ddd($uploadFile);
}

Please or to participate in this conversation.