> For the complete documentation index, see [llms.txt](https://navixy.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://navixy.com/docs/navixy-api/user-api/resources/field-service/task/form/file.md).

# Task form files

Reserve and upload a file before submitting it as a form field value.

A form field of type [file](/docs/navixy-api/user-api/resources/field-service/form/field-types.md#file), [photo](/docs/navixy-api/user-api/resources/field-service/form/field-types.md#photo), or [signature](/docs/navixy-api/user-api/resources/field-service/form/field-types.md#signature) takes a file ID as its value, not the file itself. Getting that ID is a two-step exchange, and this operation is the first step.

Calling it reserves the file and returns upload credentials: a URL and the form fields to send with it. Uploading the file is the second step. Submitting the form with the file ID as the field's value is a third, and without it the file is not part of the form at all.

Files that are left behind are cleaned up. A file created but never uploaded is deleted after the time in the `expires` response field, and a file uploaded but never referenced by a form field is deleted at the next form submission. Every file counts against the account's file storage quota.

## API actions

API base path: `/task/form/file`.

By making this call you basically "request permission" to upload a file. In return, you are provided with upload credentials (URL, form fields, etc.). Note that in order to actually "include" file as form field's value, creating and uploading file is not enough. You must then submit a form with file ID as a value of corresponding form field.

If file created but not uploaded, it will be deleted after date/time specified in "expires" response field. If file uploaded but not included as form field's value, it will be deleted on next form submission.

***

*Required sub-user rights:* `task_update`.

## Create form file

> Reserve a file against a form field and return the credentials for uploading it.\
> \
> This does not upload anything. It reserves space in the account's file quota and returns where and how to POST the file. Upload it as multipart form data to the returned \`url\`, sending the values from \`fields\` first and the file part last, named as \`file\_field\_name\` says.\
> \
> A reserved file that is never uploaded is deleted after \`expires\`. A file that is uploaded but never submitted as a form field value is deleted at the next form submission, so creating and uploading is not enough: the form must then be submitted with the file ID as the field's value.\
> \
> Allowed while the task is \`unassigned\`, \`assigned\` or \`arrived\`. A sub-user with the \`completed\_form\_update\` right may also act on a \`done\`, \`failed\` or \`delayed\` task. Anything else returns error 255. The form must also have been submitted at least once.\
> \
> Also accepts GET with the same parameters as query-string values.\
> \
> Requires the \`task\_update\` right.

```json
{"openapi":"3.1.0","info":{"title":"Navixy Platform API","version":"1.0.0"},"tags":[{"name":"Tasks","description":"Field service tasks: the places to visit, the routes and checkpoints they group into, the history of every change, and the forms field employees fill in. All resources under the /task/ path."}],"servers":[{"url":"https://api.eu.navixy.com/v2","description":"Navixy production server on European platform"},{"url":"https://api.us.navixy.com/v2","description":"Navixy production server on American platform"},{"url":"https://api.me.navixy.com/v2","description":"Navixy production server on Middle East platform"}],"security":[{"api_key":[]}],"components":{"securitySchemes":{"api_key":{"type":"apiKey","description":"Either a user session hash or an API key, with the \"NVX \" prefix, for example \"NVX 22eac1c27af4be7b9d04da2ce1af111b\". Obtain a session hash from the userAuth operation, or create an API key from the API keys operations. A small number of operations accept a session hash only and reject an API key with error code 4; each says so in its description.","name":"Authorization","in":"header"}},"schemas":{"FileUploadTarget":{"type":"object","description":"Where to upload a reserved file, and what to send with it. Shared by the service work and task form file operations.\n\n`fields` varies with the storage backend: internal storage returns a single `token`, while Amazon S3 returns the policy, key, signature and encryption headers that the upload must carry.","properties":{"file_id":{"type":"integer","description":"ID of the reserved file. Submit it as the value of the record it belongs to: a service work, or a form field."},"url":{"type":"string","description":"URL to POST the multipart upload to."},"expires":{"type":"string","description":"When this upload target stops being valid."},"file_field_name":{"type":"string","description":"Name to use for the file field in the upload request."},"fields":{"type":"object","description":"Additional fields to send with the upload. Send these before the file part, which must be last.","properties":{"token":{"type":"string","description":"Used to authenticate the upload."}},"additionalProperties":true}}}},"responses":{"ResponseError":{"description":"Error response object","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","description":"Always false."},"status":{"type":"object","description":"Error status. Present only when an error occurred.","properties":{"code":{"type":"integer","description":"An error code in this API, not an HTTP code."},"description":{"type":"string","description":"An error description."}}},"errors":{"type":"array","description":"Per-parameter detail, returned with validation failures such as error code 7. A parameter name here may be an internal field name rather than the documented parameter name.","items":{"type":"object","properties":{"parameter":{"type":"string","description":"Name of the parameter that failed validation."},"error":{"type":"string","description":"What was wrong with it."}}}}}}}}}}},"paths":{"/task/form/file/create":{"post":{"tags":["Tasks"],"summary":"Create form file","description":"Reserve a file against a form field and return the credentials for uploading it.\n\nThis does not upload anything. It reserves space in the account's file quota and returns where and how to POST the file. Upload it as multipart form data to the returned `url`, sending the values from `fields` first and the file part last, named as `file_field_name` says.\n\nA reserved file that is never uploaded is deleted after `expires`. A file that is uploaded but never submitted as a form field value is deleted at the next form submission, so creating and uploading is not enough: the form must then be submitted with the file ID as the field's value.\n\nAllowed while the task is `unassigned`, `assigned` or `arrived`. A sub-user with the `completed_form_update` right may also act on a `done`, `failed` or `delayed` task. Anything else returns error 255. The form must also have been submitted at least once.\n\nAlso accepts GET with the same parameters as query-string values.\n\nRequires the `task_update` right.","operationId":"taskFormFileCreate","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"task_id":{"type":"integer","description":"ID of the task the form is attached to.","minimum":1},"field_id":{"type":"string","description":"ID of the form field the file attaches to. The field must be file-based."},"size":{"type":"integer","description":"Maximum size in bytes of the file to be uploaded, used to reserve quota. The platform default cap is 16 MB.","minimum":1},"filename":{"type":"string","description":"Optional. Name to give the uploaded file. Without it the name comes from the upload itself."},"metadata":{"type":"object","description":"Optional. Metadata for the file, for images only.","additionalProperties":true}},"required":["task_id","field_id","size"]}}}},"responses":{"200":{"description":"Where to upload the file","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","description":"`true` if request finished successfully.","readOnly":true},"value":{"$ref":"#/components/schemas/FileUploadTarget"}}}}}},"400":{"description":"Bad request. The response body carries the API-level error code in `status.code`. Validation failures also include an `errors` array naming each offending parameter.","$ref":"#/components/responses/ResponseError"},"402":{"description":"Error 268: the file cannot be created without violating the account's file quota. Error 271: `size` is above the maximum allowed, 16 MB by default.","$ref":"#/components/responses/ResponseError"},"409":{"description":"Error 267: six or more unsubmitted files are already associated with this form field.","$ref":"#/components/responses/ResponseError"},"default":{"$ref":"#/components/responses/ResponseError"}}}}}}
```

#### Errors

These errors come in addition to the [general error codes](/docs/navixy-api/general/errors.md#error-codes):

* 201 - Not found in the database - if there is no task with such an ID, or task doesn't have form, or form has no field with such a field\_id.
* 231 - Entity type mismatch - if form field is not file-based, i.e. doesn't use file ID as its value.
* 255 - Invalid task state - if current task state is not "unassigned", "assigned" or "arrived", or if task's form not submitted at least once.
* 267 - Too many entities - if there are 6 or more unsubmitted files already associated with this form's field.
* 268 - File cannot be created due to quota violation.
* 271 - File size is larger than the maximum allowed (by default 16 MB).

### How to upload file data

Here's an example of upload you must make after receiving such response (assuming you uploading image named `actual_file_name.png`):

Internal storage example:

```http
POST /bla HTTP/1.1
Host: bla.org
Content-Length: 1325
Origin: http://bla.org
... other headers ...
Content-Type: multipart/form-data; boundary=WebAppBoundary

--WebAppBoundary
Content-Disposition: form-data; name="token"

a43f43ed4340b86c808ac
--WebAppBoundary
Content-Disposition: form-data; name="file"; filename="actual_file_name.png"
Content-Type: image/png

... contents of file goes here ...
--WebAppBoundary--
```

Amazon S3 example:

```http
POST / HTTP/1.1
Host:  https://bla.s3.amazonaws.com
Content-Length: 1972
Origin: https://bla.s3.amazonaws.com/
... other headers ...
Content-Type: multipart/form-data; boundary=WebAppBoundary

--WebAppBoundary
Content-Disposition: form-data; name="policy"
Content-Type: text/plain

eyJleHBpcmF0aW9uIjogIjIwMjMtMDMtMjdUMjE6MTU6MzYuMDczWiIsImNvbmRpdGlvbnMiOiNbeyJidWNrZXQiOiAibmF2aXh5LWZpbGVzLXRlc3QtZXUifSxbInN0YXJ0cy13aXRoIiwgIiRrZXkiLCAiIl0seyJzdWNjZXNzX2FjdGlvbl9zdGF0dXMiOiAiMjAwIn0seyJ4LWFtei1hbGdvcml0aG0iOiAiQVdTNC1ITUFDLVNIQTI1NiJ9LHsieC1hbXotY3JlZGVudGlhbCI6ICJBS0lBSUJRNlNSQjY1RVZTU1JNQS8yMDIzMDMyNy9ldS1jZW50cmFsLTEvczMvYXdzNF9yZXF1ZXN0In0seyJ4LWFtei1kYXRlIjogIjIwMjMwMzI3VDIxMDAzNloifSx7IngtYW16LXNlcnZlci1zaWRlLWVuY3J5cHRpb24iOiAiQUVTMjU2In1dfQ==
--WebAppBoundary
Content-Disposition: form-data; name="key"
Content-Type: text/plain

nj9relv6m52qp01t0wv47wyk1ozd309g/${filename}
--WebAppBoundary
Content-Disposition: form-data; name="success_action_status"
Content-Type: text/plain

200
--WebAppBoundary
Content-Disposition: form-data; name="x-amz-algorithm"
Content-Type: text/plain

AWS4-HMAC-SHA256
--WebAppBoundary
Content-Disposition: form-data; name="x-amz-credential"
Content-Type: text/plain

AKIAIBQ6SRB65EVSSRMA/20230327/eu-central-1/s3/aws4_request
--WebAppBoundary
Content-Disposition: form-data; name="x-amz-date"
Content-Type: text/plain

20230327T210036Z
--WebAppBoundary
Content-Disposition: form-data; name="x-amz-signature"
Content-Type: text/plain

2df7efa0c0e0c5b97d0d9483acd77c9ec37360df921b019a4c4a93180a6136ad
--WebAppBoundary
Content-Disposition: form-data; name="x-amz-server-side-encryption"
Content-Type: text/plain

AES256
--WebAppBoundary
Content-Disposition: form-data; name="file"; filename="actual_file_name.png"
Content-Type: image/png

... contents of file goes here ...
--WebAppBoundary--
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://navixy.com/docs/navixy-api/user-api/resources/field-service/task/form/file.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
