Technology

How to Upload IPFS Files via Spydra’s IPFS Upload API and Client Tool?

JavaScript frameworks make development easy with extensive features and functionalities. Here are our top 10 to use in 2022.
Written by
spydraadmin
Published on
January 1, 1970

How to Upload IPFS Files via SPDR’s IPFS Upload API and Client Tool?

Introduction

SPDR IPFS and other APIs will be released in January 2022. We will provide you with details API specifications and examples as well.

Description

If you’re an IPFS user who wants to upload a file or directory to IPFS, SPDR has a simple, easy-to-use Upload Client tool to help you do just that. Once your data is uploaded, you have all the same functionality as if you had uploaded your file normally, i.e. you can access it via CID, or if you’ve uploaded a directory, you can access it with its CID and “browse” within the directory by providing a path to reach a sub-folder or file.

How does it work?

The Upload Client tool will have three options for customization:

--id (your Project ID from your SPDR dashboard - instructions on accessing it below)

--secret (your Project Secret from your SPDR dashboard - instructions on accessing it below)

--url (the URL you are uploading to - this defaults to an SPDR endpoint URL)

To get the --id and --secret , you have two options:

Option One

Find your IPFS project in your SPDR dashboard and hit the “SETTINGS” button on the right of the project - That will show you the details.

Option Two

Find your IPFS project in your SPDR dashboard and select the IPFS project you are going to be using to upload your files. Once you’re in the project, go into the “PROJECT SETTINGS” tab from the top menu.

Inside your settings under the “KEYS” section, you will find both your Project ID and Secret to use in the command.

Usage

To use the Upload Client tool, we will provide you with a repo to clone. You can then follow the instructions both in the repo and below. You can install the tool via the pre-compiled binaries listed in the latest release page or you can simply run git clone, which will create the binary in your project’s folder.

Once you have that installed, you will simply run the below command in your terminal:

./spdr-ipfs-upload --id <project_id> --secret <project_secret> /path/to/data

Once you’ve done that, you will get a printout of your hash in an “IPFS” directory, showing you have successfully uploaded your files to SPDR’s IPFS endpoint. You will be able to access your files via your dashboard, under your IPFS project.

API Endpoints

The SPDR API endpoint will be:

https://ipfs.thespiderman.io/profile

As an example, to download a file that has been written to IPFS, simply provide the IPFS hash to the API

https://ipfs.thespiderman.io/ipfs/<hash>

The UI/JSON integration with the API looks like the following:

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<meta http-equiv="X-UA-Compatible" content="ie=edge">

<title>Document</title>

</head>



<body>


<form action="/profile" method="post" enctype="multipart/form-data">


<input type="file" name="avatar" />


<button>upload</button>


</form>


<input id="filehash"type="text">


<button onclick="loadDoc()">download</button>


</body>


<script>


function loadDoc() {


var xhttp = new XMLHttpRequest();


xhttp.onreadystatechange = function() {


if (this.readyState == 4 && this.status == 200) {


// document.getElementById("demo").innerHTML = this.responseText;


console.log(this);


window.open(this.responseURL);


}

};

console.log(document.getElementById("filehash").value)

xhttp.open("GET", "download/"+document.getElementById("filehash").value, true);

xhttp.send();

}

</script>

</html>

Latest posts

Subscribe to Our Newsletter

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.