# create()

Canonical URL: https://developers.iagenify.com/sdk/ref/files/create/
Language: en

`api.files.create({ name, content, mimeType }) → IaGenifyFile`

Builds a file object in memory. Nothing is sent, nothing is written, nothing is charged — this is the step before all of that.

Status: no network · synchronous · returns an object to fill

## Parameters {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `name` | string |  | The file name. Used as-is on the account; the server reduces it to a safe one on its own disk. |
| `content` | string|Buffer|Blob |  | The bytes. Can be set after construction — it is read at `save()`, not here. |
| `mimeType` | string |  | Defaults to `application/octet-stream`, which makes the category `document`. |

It returns synchronously and there is no `await`: this is a constructor in all but name.

## The object {#returns}

```javascript
const file = api.files.create({ name: "notes.md", content: "…", mimeType: "text/markdown" });

file.name;
file.content;
file.mimeType;
file.sourceId;   // null until it is saved
file.location;   // null until it is saved
file.metadata;   // null until it is saved
```

## Set the mimeType, even though it is optional {#mime}

It decides two things that are awkward to change later: the [category](/sdk/ref/files), and whether `get()` hands the content back as text or as bytes.

| You pass | Category | get() returns |
| --- | --- | --- |
| text/markdown | document | content as a string |
| application/json | data | content as a string |
| image/png | image | content as a Buffer |
| (nothing) | document | content as a Buffer |

> **Leaving it out makes text come back as bytes**
>
> Without a type the default is a binary one, so a perfectly readable Markdown file is handed back as a Buffer. One line of work now, or a confusing read later.

## What content accepts {#content}

```javascript
// A string
api.files.create({ name: "notes.md", content: "# Notes", mimeType: "text/markdown" });

// Bytes you already have
api.files.create({ name: "chart.png", content: pngBuffer, mimeType: "image/png" });

// Something generated — write it out the moment you have it
const { outputs } = await assistant.generate({ inputs, outputs: [{ type: "image" }] });
api.files.create({ name: "cover.png", content: outputs[0].content, mimeType: outputs[0].mime });
```

## Filling it in afterwards {#later}

The content is read when you save, so building the object first and filling it later is fine — and it is how `update()` works.

```javascript
const file = api.files.create({ name: "log.txt", mimeType: "text/plain" });

file.content = lines.join("\n");
await file.save();

// And to replace it later
file.content = "…";
await file.update();
```

> **Saving with no content is refused locally**
>
> The SDK throws before any request when content is undefined or null — an empty string, on the other hand, is a legitimate empty file.

- [file.save()](/sdk/ref/files/save): Where it becomes real.
- [Output types](/sdk/concepts/outputs): Getting generated media out of a result and into a file.

```python
file = api.files.create(name="notes.md", content="…", mime_type="text/markdown")

file.name
file.content
file.mime_type
file.source_id   # None until it is saved
file.location    # None until it is saved
file.metadata    # None until it is saved
```

```python
import base64

# A string
api.files.create(name="notes.md", content="# Notes", mime_type="text/markdown")

# Bytes you already have
api.files.create(name="chart.png", content=png_bytes, mime_type="image/png")

# Something generated — write it out the moment you have it
outputs = assistant.generate(inputs=inputs, outputs=[{"type": "image"}])["outputs"]
api.files.create(name="cover.png", content=base64.b64decode(outputs[0]["content"]), mime_type=outputs[0].get("mime"))
```

```python
file = api.files.create(name="log.txt", content="", mime_type="text/plain")

file.content = "\n".join(lines)
file.save()

# And to replace it later
file.content = "…"
file.update()
```
