# FormData

Sirve para enviar datos binarios mediante [XMLHttpRequest](/36/velneo-vdevelop/scripts/lenguajes/javascript/clases/xmlhttprequest.md).&#x20;

Requiere importarla previamente a su uso:&#x20;

```javascript
importClass("FormData");
```

## Indice de funciones

### Constructor

FormData FormData()

### Generales

append( clave, VFile( Senda ) )

append( clave, texto )

## Documentación de funciones

### Constructor

FormData [FormData](/36/velneo-vdevelop/scripts/lenguajes/javascript/clases/formdata.md)()

### Funciones generales

#### append( clave, [VFile](/36/velneo-vdevelop/scripts/lenguajes/javascript/clases/vfile.md)( Senda ) )

Permite añadir un fichero al envío de una petición XMLHttpRequest.

Parámetros:

* clave: nombre del parámetro correspondiente al binario a enviar.
* [VFile](/36/velneo-vdevelop/scripts/lenguajes/javascript/clases/vfile.md)( Senda ): senda del fichero a enviar.

Para enviar el FormData hay que pasarlo como parámetro en la funcion [send( VByteArray data )](/36/velneo-vdevelop/scripts/lenguajes/javascript/clases/xmlhttprequest.md#send-1) de la clase [XMLHttpRequest](/36/velneo-vdevelop/scripts/lenguajes/javascript/clases/xmlhttprequest.md).

#### append( clave, texto )

Permite añadir un texto al envío de una petición XMLHttpRequest.

Parámetros:

* clave: nombre del parámetro a enviar en la petición.
* texto: valor del parámetro.

Para enviar el FormData hay que pasarlo como parámetro en la funcion void [send( String data )](/36/velneo-vdevelop/scripts/lenguajes/javascript/clases/xmlhttprequest.md#send) de [XMLHttpRequest](/36/velneo-vdevelop/scripts/lenguajes/javascript/clases/xmlhttprequest.md).

## Ejemplo

Un proceso JavaScript que envía un fichero en una petición XMLHttpRequest. Los datos de URL, etc. los toma de variables locales definidos en el mismo.

```javascript
importClass("VFile");
importClass("XMLHttpRequest");
importClass("FormData");
 
function uploadFile(filename) {
    // Create FormData object
    var formData = new FormData();

    // Append the filename directly (empty content)
    formData.append('file', new VFile(filename));

    // Create XMLHttpRequest object
    var xhr = new XMLHttpRequest();
    
    // Configure the request
    xhr.open('POST', theRoot.varToString("URL"), false);

	 // Send the FormData with the file
    xhr.send(formData);
	
	if ( (xhr.errorCode==0) && (xhr.status == 200) ) {
		theRoot.setVar("RES", "Subido con FormData " + xhr.responseText );
	}else{
		alert("Error");
	}
      
  }

  // Ejemplo de uso
  var filename = theRoot.varToString("SND");  
  uploadFile(filename);
```


---

# 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://doc.velneo.com/36/velneo-vdevelop/scripts/lenguajes/javascript/clases/formdata.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.
