# How to solve file upload problem?

**URL:** <https://community.grafana.com/t/how-to-solve-file-upload-problem/97768>\
**Category:** OSS Support\
**Created:** [May 9, 2022, 10:31am UTC](https://community.grafana.com/t/how-to-solve-file-upload-problem/97768 "2022-05-09T10:31:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yusuf](https://avatars.discourse-cdn.com/v4/letter/y/c68b51/32.png) [@Yusuf](https://community.grafana.com/u/Yusuf)\
**Post date:** [May 9, 2022, 10:31am UTC](https://community.grafana.com/t/how-to-solve-file-upload-problem/97768/1 "2022-05-09T10:31:19Z")

</div>

I have a problem with k6 file upload. By the way formData.body() returns [object ArrayBuffer] in the console  
Taking 500 error which inclues below;

```auto
"code":500,"applicationErrorCode":-1,"message":"Unknown Error","exceptionContent":"System.NullReferenceException: Object reference not set to an instance of an object.\n 

```

My code below;

```auto
import { describe } from "https://jslib.k6.io/expect/0.0.4/index.js";
import { FormData } from 'https://jslib.k6.io/formdata/0.0.2/index.js';
import exec from "k6/execution";
import { check } from 'k6';
import http from "k6/http";
import Load, { Roles } from "../../../core/load.js";
let endpoints = JSON.parse(open("../../../core/endpoint.json"));

let file = open('../../../utils/waybill.jpg','b')

export function setup() {
    let supportAuth = Load.auth(Roles.Support);
    let waysSeedRes = http.post(
        Load.api + endpoints.Debug.Seed + '?seeds=Ways',
        {
            headers: {
                Authorization: `Bearer ${supportAuth.json().access_token}`,
                "Content-Type": "application/json",
                apikey: "test"
            }
        }
    );
   
    return [
        supportAuth.json(),
        waysSeedRes .json()
    ];
}

const totalVu = 1;
export const options = {
    summaryTimeUnit: "ms",
    scenarios: {
        Ways: {
            exec: "Ways",
            executor: "per-vu-iterations",
            vus: totalVu,
            iterations: 1,
        },
    },
};

export function Ways(data) {
    let tokenForSupport = data[0].access_token;

    describe("Ways scenerio", (t) => {

        const formData = new FormData()
        formData.append('file', file)
        const res = http.post(Load.api + endpoints.Waybills.uploadWaybillImage, formData.body(), {
            headers: {
                Authorization: `Bearer ${tokenForSupport}`,
                 apikey: "test",
                'Content-Type': 'multipart/form-data'
            },
        });
        console.log("fileUpload",res.body)
        check(res, {
            'is status 200': (r) => r.status === 200,
          });

    });
}

```

---

<div class="post-metadata">

**Author:** ![olegbespalov](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/olegbespalov/32/36739_2.png) [@olegbespalov](https://community.grafana.com/u/olegbespalov)\
**Post date:** [May 10, 2022, 1:10pm UTC](https://community.grafana.com/t/how-to-solve-file-upload-problem/97768/3 "2022-05-10T13:10:10Z")

</div>

Hi @Yusuf !

Have you tried to use `http.file`? See documentation [Data Uploads](https://k6.io/docs/examples/data-uploads#multipart-request-uploading-a-file).

> “code”:500,“applicationErrorCode”:-1,“message”:“Unknown Error”,“exceptionContent”:"System.NullReferenceException: Object reference not set to an instance of an object.\n

Is it from the response logs? 🤔 I guess the actual error is presented in the server logs.

Let me know know if that answers,  
Cheers!

---

<div class="post-metadata">

**Author:** ![Yusuf](https://avatars.discourse-cdn.com/v4/letter/y/c68b51/32.png) [@Yusuf](https://community.grafana.com/u/Yusuf)\
**Post date:** [May 16, 2022, 10:14pm UTC](https://community.grafana.com/t/how-to-solve-file-upload-problem/97768/5 "2022-05-16T22:14:27Z")

</div>

@olegbespalov tried http.file but got same error. I guess , this is related to our server error. You are right
