Open danielcuautle opened 5 years ago
Is your server url correct? If yes, then your server side code might produce some error. Try to simplify your code, so you can locate the source of the error for specific.
Can you post the server side code for handling the upload and the Javascript code you're using?
CLIENT:
SERVER:
using RedRingQuiscoDB.Modelos.Seguridad; using RedRingQuiscoDB.Utileria; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; using System.Web.Hosting; using System.Web.Script.Services; using System.Web.Services;
namespace RedRingQuioscoWeb.Views.Home
{
///
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void Save()
{
try
{
HttpContext Contexto = HttpContext.Current;
HttpFileCollection vFilesCollection = Context.Request.Files;
Usuario usuario = (Usuario)(HttpContext.Current.Session["Login_Usuario"]);
string vPath = HostingEnvironment.MapPath($"~/Recursos/temp/{usuario.IdUsuario}");
if (Directory.Exists(vPath))
{
string[] filePaths = Directory.GetFiles(vPath);
foreach (string filePath in filePaths)
File.Delete(filePath);
}
string vNameFile = string.Empty;
for (int x = 0; x < vFilesCollection.Count; x++)
{
vNameFile = vFilesCollection[x].FileName;
string vFileInfo = System.IO.Path.GetFileName(vFilesCollection[x].FileName);
string vFolderToSave = $"{Server.MapPath("Recursos")}\\{vFileInfo}";
if (!Directory.Exists(vPath))
{
Directory.CreateDirectory(vPath);
}
string[] words = vNameFile.Split('.');
string vTypeFile = words[words.Length - 1];
vFilesCollection[x].SaveAs($"{vPath}/{vFileInfo}");
Contexto.Response.ContentType = "application/json";
Contexto.Response.Write("{\"success\":true,\"msg\":\"" + vNameFile + "\",\"fileName\":\"" + vNameFile + "\",\"folderName\":\"" + usuario.IdUsuario + "\",\"typeFile\":\"" + vTypeFile + "\"}");
Contexto.Response.End();
}
}
catch (Exception ex)
{
Log.Instances.RegistroError(ex);
}
}
}
}
I'm try to upload file to server, but the browser console write this:
SimpleAjaxUploader.js:1828 POST ..../SaveFiles.asmx/Save 500 (Internal Server Error) _uploadXhr @ SimpleAjaxUploader.js:1828 _initUpload @ SimpleAjaxUploader.js:1882 submit @ SimpleAjaxUploader.js:1160 (anonymous) @ SimpleAjaxUploader.js:2046