# createUploader()&#x20;

> Here is an example for uploading a file:

#### Frontend:

```typescript
import { createUploader } from '@magicjs.dev/frontend';
import uploadServer from "./upload.server";

// The backend server function for handling file uploads
const { addFiles, upload, readyToUpload, uploadProgress, loading } = createUploader(uploadServer);

const handleUploadFile = () => {
  upload();
};

return (
  <div>
    <input
      type='file'
      onChange={(e) => {
        addFiles(e.target.files);
        // Adds selected files to the uploader instance
      }}
    />
    <button
      onClick={handleUploadFile}
      disabled={Boolean(readyToUpload) === false || loading === true}
    >
      {/* readyToUpload is a boolean variable; it becomes true if any images are selected,
      and false if none are chosen.
      The boolean variable loading becomes true while the API is in progress and turns false once the operation is complete. */}
      Upload
    </button>
    <div>{uploadProgress}</div>
    {/* The numeric variable uploadProgress indicates the progress of the upload,
    providing visibility into the ongoing upload process. */}
  </div>
);
```

#### Backend `upload.server`

```typescript
import { createBackendFunction, createRequestContext, useFunctionContext, utils } from '@magicjs.dev/backend';

export default createBackendFunction(async function () {
  createRequestContext(this)
    .uploader()
    .onFile((info, file) => {
      // Will get the file information from the parameter info.
      utils.saveFileToUserUploads('/upload-path', 'imageName.jpeg', file);
    });
})
```

[Click here to refer GitHub](https://github.com/skyslit/magicjs.dev/blob/main/packages/frontend/src/file-uploader.tsx#L4).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://skyslit.gitbook.io/magicjs/api-references/frontend/createuploader.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
