How to send an array of files using FormData?

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

How to Send an Array of Files Using FormData in Laravel Applications

As developers building modern web applications, handling file uploads—especially multiple files—is a common yet often tricky task. When you move from simple text inputs to complex form submissions involving arrays of files, the mechanics of HTTP requests become critical. This guide will walk you through the correct way to package an array of files using FormData on the frontend (Vue.js) and how your Laravel backend should be structured to receive this data efficiently.

The Challenge: Sending File Arrays via FormData

The core issue many developers face is attempting to append a JavaScript array directly to FormData. When you use methods like frmData.append('file_ticket', this.filelist), the browser serializes the array into a string representation (e.g., "FileA,FileB" or an object string), which Laravel cannot interpret as actual file data. The server expects the request to be sent as multipart/form-data, where each file is treated as a distinct stream of binary data.

To successfully send multiple files, you must iterate over your array and append each individual File object to the FormData instance.

Frontend Implementation: Correctly Populating FormData (Vue.js)

In your Vue component, when handling the file selection event, you need to ensure that every file in your collected array is appended separately with a unique name that your backend can recognize.

Here is the corrected approach for collecting and sending multiple files:

// Assume this.filelist is an array of File objects collected from input elements
const getFiles = [...this.$refs.file.files]; // Get all selected files

if (!getFiles || getFiles.length === 0) {
    console.warn("No files selected.");
    return;
}

let frmData = new FormData();

// Append standard text fields first
frmData.append('subject', this.newTicket.subject);
frmData.append('service', this.newTicket.service);
frmData.append('description', this.newTicket.description);
frmData.append('client_id', this.idUser);

// *** THE CRITICAL STEP: Append each file individually ***
getFiles.forEach((file, index) => {
    // Use a consistent naming convention for the file field on the server
    frmData.append('file_ticket[]', file); 
});

// Define the endpoint
const url = `ticket/new_ticket`;

axios.post(url, frmData)
    .then((response) => {
        console.log("Upload successful:", response);
    })
    .catch((error) => {
        console.error("Upload failed:", error);
    });

Key Takeaway: Notice the use of frmData.append('file_ticket[]', file);. Appending files using an array notation ([]) is a convention that assists in many server-side frameworks, including Laravel, when expecting multiple files under the same field name. This ensures that each file is correctly formatted within the overall multipart/form-data payload.

Backend Implementation: Receiving Files in Laravel

On the Laravel side, receiving this data is straightforward once you understand how multipart/form-data works. When using request()->file('field_name') or $request->file('field_name'), Laravel automatically handles parsing the stream of files sent from the client.

In your controller method (e.g., TicketController@store), you can access the uploaded files like this:

use Illuminate\Http\Request;

class TicketController extends Controller
{
    public function store(Request $request)
    {
        // Validate standard text fields
        $validatedData = $request->validate([
            'subject' => 'required',
            'service' => 'required',
            'description' => 'required',
            'client_id' => 'required',
            // The file_ticket field will now be an array of uploaded files
            'file_ticket' => 'required|array', 
        ]);

        $subject = $request->input('subject');
        $description = $request->input('description');
        $clientId = $request->input('client_id');
        
        // Accessing the array of files using the bracket notation
        $ticketFiles = $request->file('file_ticket');

        // Process the files (e.g., move them to storage)
        foreach ($ticketFiles as $file) {
            // Example: Store each file on the disk
            $path = $file->store('tickets', 'public');
            \Log::info("File uploaded: " . $path);
        }

        // ... rest of your ticket saving logic
        return response()->json(['message' => 'Ticket created successfully']);
    }
}

Conclusion

Sending arrays of files via FormData requires a specific approach: iterate through your JavaScript array and append each File object individually to the FormData. This ensures that the HTTP request is correctly structured as multipart/form-data, which is the standard mechanism for file uploads. By aligning the frontend data preparation with how Laravel expects to receive multipart requests, you create a robust and scalable API. For deeper insights into structuring robust APIs within the Laravel ecosystem, I highly recommend exploring resources from laravelcompany.com.