webservice (asmx)를 사용하여 파일을 업로드하고 MD5를 확인한 다음이를 확인하는 작은 업로드 응용 프로그램이 있습니다. 문제는 내가 파일을 검증 할 때 그 파일이 다른 프로세스에 의해 잠겨 있다고 말한다.업로드 된 파일을 잠그는 IIS의 문제점
private static object padlock = new object();
작은 바이트에서 업로드 파일을 청크와 내 데이터베이스에 삽입 마지막 후
[WebMethod]
public void LargeUpload(byte[] content, string uniqueName)
{
lock (padlock)
{
string path = Server.MapPath(PartialDir + "/" + uniqueName);
BinaryWriter writer = new BinaryWriter(File.Open(path, FileMode.Append, FileAccess.Write));
writer.Write(content);
writer.Flush();
writer.Close();
writer = null;
}
}
그들 각각 업로드 : 다음 업로드 및 검증에 대한 내 코드입니다. EndLargeUpload() 메소드 클라이언트가 파일의 ID,이 파일을 열 수없는 예외이 전화 excepts로 RequestMD5 메소드를 호출 한 후
[WebMethod]
public int EndLargeUpload(string name, int folderId, long length, string uniqueName, int customerid)
{
lock (padlock)
{
string path = Server.MapPath(PartialDir + "/" + uniqueName);
string newPath = Server.MapPath(RepositoryDir + "/" + uniqueName);
File.Copy(path, newPath);
//delete partial
File.Delete(path);
string extension = Path.GetExtension(uniqueName);
string newFileName = uniqueName;
GWFile newFile = new GWFile();
newFile.DiscName = newFileName;
newFile.FileName = name;
newFile.FolderId = folderId;
newFile.Description = "";
newFile.Size = (int)length;
newFile.DiscFolder = Server.MapPath("/Repository");
newFile.DiscRelativePath = "/Repository/" + newFile.DiscName;
newFile.CustomerId = customerid;
IGWFileRepository fileRepository = ObjectFactory.GetInstance<IGWFileRepository>();
fileRepository.SaveFile(newFile);
return newFile.Id;
}
}
이 후 클라이언트는 MD5를 요청하여 파일을 확인합니다 이
private string GetMD5HashFromFile(string fileName)
{
lock (padlock)
{
using (FileStream file = new FileStream(fileName, FileMode.Open)) // <-- excepts here
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] retVal = md5.ComputeHash(file);
file.Close();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < retVal.Length; i++)
{
sb.Append(retVal[i].ToString("x2"));
}
return sb.ToString();
}
}
}
내가 파일을 볼 시스 인 터널에서 프로세스 탐색기를 사용 ... 다른 프로세스에 의해 사용되는 s의 때문에 "..... XXX ...", 파일이에 의해 잠겨 있음을 말한다 웹 서버 (pls는이 img :
http://screencast.com/t/oqvqWXLjku를 참조하십시오) - 어떻게 웹 서버가 그것을 잠글 수 있습니까? 이 문제를 해결할 수 있을까요?
힌트를 –
이 파일을 터치 할 수있는 다른 파일 I/O가이 애플리케이션에 있습니까? – Ryan
이런 종류의 프로젝트에서는'Cassini' 대신'IIS'를 사용하는 것이 좋습니다 – Xaqron