# Upload file to IPFS Storage

This allows to upload a file to IPFS storage. The weightage for this API is `10`

## API Specification

## Upload file to IPFS Storage

<mark style="color:green;">`POST`</mark> `https://api.krypcore.com/api/v0/storagemanageripfs/storefile`

This allows to upload file to IPFS storage under the given instance.&#x20;

#### Headers

| Name                                            | Type   | Description                      |
| ----------------------------------------------- | ------ | -------------------------------- |
| DappId                                          | String | DappId                           |
| Authorization<mark style="color:red;">\*</mark> | String | Authorization key from dashboard |

#### Request Body

| Name                                    | Type | Description     |
| --------------------------------------- | ---- | --------------- |
| files<mark style="color:red;">\*</mark> | file | Upload the file |

{% tabs %}
{% tab title="200: OK File Uploaded Successfully" %}

```javascript
{
    "Data": "QmbVnEgY9K1Qypb6Rqf81U8SfmoUfYNgTdsJm3JtvSTYKZ",
    "Message": "IPFS storage created successfully",
    "Status": "SUCCESS"
}
```

{% endtab %}

{% tab title="400: Bad Request Input file is missing" %}

```javascript
null
```

{% endtab %}

{% tab title="401: Unauthorized Authorization key is missing" %}

```javascript
{
    "message": "Missing API key found in request"
}
```

{% endtab %}
{% endtabs %}

Take a look at how you might call this method using our official libraries, or via `curl`:

{% tabs %}
{% tab title="curl" %}

```bash
curl --location --request POST 'https://api.krypcore.com/api/v0/storagemanageripfs/storefile' \
--header 'Authorization: xxxxx-xxxx-xxxx-xxxx-xxxxxxxx' \
--header 'DappId: xxx_xx_xx_xxxxxxx' \
--form 'files=@"/home/rajdeep/Downloads/download.png"'
```

{% endtab %}

{% tab title="Node.js (Fetch)" %}

```javascript
var axios = require('axios');
var FormData = require('form-data');
var fs = require('fs');
var data = new FormData();
data.append('files', fs.createReadStream('/home/rajdeep/Downloads/download.png'));

var config = {
  method: 'post',
  url: 'https://api.krypcore.com/api/v0/storagemanageripfs/storefile',
  headers: { 
    'Authorization': 'xxxxxx-xxxx-xxxx-xxxx-xxxxxxx', 
    'DappId': 'xxx_xx_xx_xxxxxxx', 
    ...data.getHeaders()
  },
  data : data
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});

```

{% endtab %}

{% tab title="Python " %}

```python
import requests

url = "https://api.krypcore.com/api/v0/storagemanageripfs/storefile"

payload={}
files=[
  ('files',('download.png',open('/home/rajdeep/Downloads/download.png','rb'),'image/png'))
]
headers = {
  'Authorization': 'xxxxxxx-xxxx-xxxx-xxxx-xxxxxxx',
  'DappId': 'xxx_xx_xx_xxxxxxx'
}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)


```

{% endtab %}

{% tab title="Golang" %}

```go
package main

import (
  "fmt"
  "bytes"
  "mime/multipart"
  "os"
  "path/filepath"
  "io"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.krypcore.com/api/v0/storagemanageripfs/storefile"
  method := "POST"

  payload := &bytes.Buffer{}
  writer := multipart.NewWriter(payload)
  file, errFile1 := os.Open("/home/rajdeep/Downloads/download.png")
  defer file.Close()
  part1,
         errFile1 := writer.CreateFormFile("files",filepath.Base("/home/rajdeep/Downloads/download.png"))
  _, errFile1 = io.Copy(part1, file)
  if errFile1 != nil {
    fmt.Println(errFile1)
    return
  }
  err := writer.Close()
  if err != nil {
    fmt.Println(err)
    return
  }


  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("Authorization", "xxxxx-xxxx-xxxx-xxxx-xxxxxx")
  req.Header.Add("DappId", "xxx_xx_xx_xxxxxxx")

  req.Header.Set("Content-Type", writer.FormDataContentType())
  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}
```

{% endtab %}
{% endtabs %}
