When trying to use the ImageKit API on my server side, I keep getting the following error: XMLHttpRequest is not defined
. I have installed xmlhttprequest
with npm and tried require('xmlhttprequest')
and require('xmlhttprequest').XMLHttpRequest
, but neither has worked. What can I do here?
Here is the backend upload method straight from the documentation. Even using just this version (replacing the ImageKit fields with my personal ones) gave the same error. I am trying to upload from my server-side, which supposedly this method is designed for.
var ImageKit = require("imagekit");
var fs = require('fs');
var imagekit = new ImageKit({
publicKey : "your_public_api_key",
privateKey : "your_private_api_key",
urlEndpoint : "https://ik.imagekit.io/your_imagekit_id/"
});
var base64Img = "iVBORw0KGgoAAAAN";
imagekit.upload({
file : base64Img, //required
fileName : "my_file_name.jpg", //required
tags: ["tag1","tag2"]
}, function(error, result) {
if(error) console.log(error);
else console.log(result);
});
2