I have the screen below:
Ineedtheusertoselectasongandacover,butI'mnotfindingawaytosendthetwofilesatonceandstillvalidateifMusicandCoverhavebeenselected.
UntilthenIfollowedtheexamplebelow,butJSonlytakesthecontentofthe(upFoto)input,howeverIcreatedthesameexcerptwithdifferentnamestogettheMusicinputupMusica,butJSdoesnotsendanMP3file,anerroroccursinthepushbutton(lbtSend)button.
Wouldanyonehaveasuggestionforthiscase?
$(function(){$('#lbtEnviar').click(function(){varfileUpload=$("#upFoto").get(0);
var files = fileUpload.files;
var test = new FormData();
for (var i = 0; i < files.length; i++) {
test.append(files[i].name, files[i]);
}
$.ajax({
url: "UploadArquivo.ashx",
type: "POST",
contentType: false,
processData: false,
data: test,
// dataType: "json",
success: function (result) {
alert(result);
},
error: function (err) {
alert(err.statusText);
}
});
});
})
C # snippet that receives the file:
public void ProcessRequest(HttpContext context)
{
try
{
if (context.Request.Files.Count > 0)
{
HttpFileCollection files = context.Request.Files;
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile file = files[i];
string fname;
if (HttpContext.Current.Request.Browser.Browser.ToUpper() == "IE" || HttpContext.Current.Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER")
{
string[] testfiles = file.FileName.Split(new char[] { '\' });
fname = testfiles[testfiles.Length - 1];
}
else
{
fname = file.FileName;
}
string pathToSave = "D:\Msik_Arquivos" + "\" + fname;
file.SaveAs(pathToSave);
}
}
context.Response.ContentType = "text/plain";
context.Response.Write("File Uploaded Successfully!");
}