How can i use Dedicated gateway for ipfs js Plz help

now i am try to make website for minting and trade NFT.

but now i can not use dedicated gateway.

This is the process to get the iPFS URL by sending the selected IMAGE to Infura.

but now it shows error becoz public infura doesn’t work .

I used public infura like this

//ipfs
	const IPFS_URL = "https://ipfs.io/ipfs/";
	const IPFS_API_URL = "ipfs.infura.io";
	const ipfs = window.IpfsApi(IPFS_API_URL, "5001", { protocol: "https" }); // Connect to IPFS

	$("#btn_uploadfile").on("click", function () {
		if ($("#uploadfile").val() == "") {
			alert("selcet image");
			$("#uploadfile").focus();
			return;
		}

		var reader = new FileReader();
		reader.onloadend = function () {
			//console.log("reader.result" + reader.result);
			var buf = buffer.Buffer(reader.result); // Convert data into buffer
			ipfs.files.add(buf, (err, result) => {
				// Upload buffer to IPFS
				if (err) {
					console.error(err);
					return;
				}

				var hash_img_url = IPFS_URL + result[0].hash;

				//console.log(`Url --> ${hash_img_url}`);
				$("#ipfs_file_url").text(hash_img_url);
				$("#ipfs_file_url").attr("href", hash_img_url);
				$("#hash_img_url").val(hash_img_url);
			});
		};

		//console.log($('input#uploadfile')[0].files[0]);
		reader.readAsArrayBuffer($("input#uploadfile")[0].files[0]); // Read Provided File
	});

now public infura is not working so i made dedicated gateway like this

https://benjaminkor2.infura-ipfs.io

but i don’t know how it use and where should i put this.

Plz help me

Hey @Mr_Tai to access your files on the dedicated getaway your URL should look as follows:

https://benjaminkor2.infura-ipfs.io/ipfs/CID → where CID is the CID return after pinning/uploading a file.

Thank you i tryed it . but after it they show me that error

POST https://ipfs.infura.io:5001/api/v0/add?stream-channels=true 401 (Unauthorized)

now my code like this .
after upload button infura works but return 401 error

Thank you for your Help.

I solved problem !!. :slight_smile:

@Mr_Tai Apologies for the late reply!
I’m glad that you have resolved the issue.

Just to note, you were missing authentication in your buf; that should include project id and project secret to authenticate requests!

How did you solve the problem?