Tengo un archivo almacenado en la variable this.form.imagesFile . Contiene el archivo a continuación: 
Y quiero enviarlo usando FormData y AJAX . FYI: Estoy usando Vue y Laravel.
let getImg = []; this.form.variantsProd.forEach((item) => { let totalImagesFile = $('.images' + item.id)[0].files.length; //Total Images let imagesFile = $('.images' + item.id)[0]; for (let i = 0; i < totalImagesFile; i++) { getImg.push(imagesFile.files[i]); } this.form.imagesFile = getImg; }); this.form.totalImagesFile = getImg.length; let formData = new FormData(); formData.append('imagesFile', this.form.imagesFile); $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content'), }, }); const token = localStorage.getItem('token-staff'); var self = this; $.ajax({ url: `${BASE_URL}/api/staff/products/store`, method: 'post', data: formData, enctype: 'multipart/form-data', cache: false, contentType: false, processData: false, dataType: 'JSON', async: true, headers: { 'Content-Type': undefined, }, xhr: function () { let myXhr = $.ajaxSettings.xhr(); return myXhr; }, beforeSend: function (xhr) { xhr.setRequestHeader('Authorization', `Bearer ${token}`); }, error: function (response) { console.log(response); }, success: function (result) { if (result.errors) { console.log(result); } else { // } //endif }, }); Pero cuando trato de obtener el archivo en el controlador, obtengo [object File] . Entonces, hago gettype($imagesFile) y el resultado es string . Este es obviamente un resultado inesperado. Quiero almacenar el archivo en el servidor. ¿Cómo puedo hacer eso?
public function store(Request $request) { $imagesFile = $this->request->get('imagesFile'); return response()->json([ 'success' => true, 'message' => $imagesFile, ]); }this.form.imagesFile es una matriz que debe pasar un archivo al objeto FormData. Además, no establezca el tipo de contenido.
let formData = new FormData(); this.form.variantsProd.forEach((item) => { let totalImagesFile = $('.images' + item.id)[0].files.length; //Total Images let imagesFile = $('.images' + item.id)[0]; for (let i = 0; i < totalImagesFile; i++) { getImg.push(imagesFile.files[i]); formData.append('imagesFile', imagesFile.files[i]); } this.form.imagesFile = getImg; }); ... $.ajax({ url: `${BASE_URL}/api/staff/products/store`, method: 'post', data: formData, cache: false, contentType: false, processData: false, dataType: 'JSON', async: true, beforeSend: function (xhr) { xhr.setRequestHeader('Authorization', `Bearer ${token}`); }, error: function (response) { console.log(response); }, success: function (result) { if (result.errors) { console.log(result); } else { // } //endif }, }); Puede acceder al archivo a través $request->file('imagesFile');