0
How can I insert images like append
in a Formdata?
I’m trying this way, but when I use the console.log
to verify the variable dados
, the imagens
is empty.
var dados = new FormData();
$('.copiar-elemento').each(function() {
$(this).find('input:file').each(function(index, element) {
dados.append('cores[imagens][]', element.files[0]);
});
});
Would not be
$(this).find("select[name*='tamanho']").each(function(index, element) { dados.append('cores[tamanhos][]', element.value); });
??– NoobSaibot
That’s right, thanks! I tried to use the same structure to do the same with a file field. Would you have to modify something else to work? I put the code in the question.
– Diego Vieira
Simply inform the third parameter
dados.append('cores[imagens][]', element.files[0], 'imagem.jpg');
see the documentation– NoobSaibot
Even with third parameter does not insert inside the formdata. When I use the.log console in the "data" shows the empty "images".
– Diego Vieira