작은 문제가있는 사람이면 누구나 스트림을 허용 할 수있는 WCF Rest Based Service가 있습니다. 이미지/오디오/비디오 업로드에 사용됩니다. 서버에 저장 한 다음 어딘가에 서버에 저장합니다.WCF 스트림을 통한 파일 업로드, 이미지 보이지 않음
및 이미지로 테스트하고 작동하는 것처럼 보입니다. 클라이언트에서 이미지를 선택하고 몇 초 후 예상 된 위치에 이미지가 서버에 나타나지만 Windows에서 이미지를 열려고 시도 할 때 그림 뷰어 (또는 모든 이미지 뷰어), 나는 "미리보기 없음"을 볼 수있는 이미지가 없습니다.
스트림에서 파일을 다시 제대로 만들지 않아서 가정합니다.
이
는 WCF 나머지 서비스public void PutFileInFolder(int eid, Stream fileContents)
{
try
{
byte[] buffer = new byte[32768];
MemoryStream ms = new MemoryStream();
int bytesRead = 0;
int totalBytesRead = 0;
do
{
bytesRead = fileContents.Read(buffer, 0, buffer.Length);
totalBytesRead += bytesRead;
ms.Write(buffer, 0, bytesRead);
} while (bytesRead > 0);
//now have file in memorystream
//save the file to the users folder
FileStream file = new FileStream(@"C:\bd_sites\ttgme\wwwroot\Evidence\{" + ed.LearnerID + @"}\" + ed.EvidenceFileName, FileMode.Create, System.IO.FileAccess.Write);
byte[] bytes = new byte[ms.Length];
ms.Read(bytes, 0, (int)ms.Length);
file.Write(bytes, 0, bytes.Length);
file.Close();
ms.Close();
}
catch (Exception ex)
{
return;
}
}
의 방법입니다 그리고 이것은 또한
private void PostFile(EvidenceObject eo)
{
try
{
// Create the REST request.
string url = ConfigurationManager.AppSettings["serviceUrl"];
string requestUrl = string.Format("{0}/PutFileInFolder/{0}", 1001);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUrl);
request.Method = "POST";
request.ContentType = "text/plain";
byte[] fileToSend = File.ReadAllBytes(txtFileName.Text);
request.ContentLength = fileToSend.Length;
using (Stream requestStream = request.GetRequestStream())
{
// Send the file as body request.
requestStream.Write(fileToSend, 0, fileToSend.Length);
requestStream.Close();
}
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
Console.WriteLine("HTTP/{0} {1} {2}", response.ProtocolVersion, (int)response.StatusCode, response.StatusDescription);
MessageBox.Show("File sucessfully uploaded.", "Upload", MessageBoxButton.OK, MessageBoxImage.Information);
this.DialogResult = true;
}
catch (Exception ex)
{
MessageBox.Show("Error during file upload: " + ex.Message, "Upload", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
그냥 비디오 파일을 테스트 파일/이미지를 전송하기위한 클라이언트 기능의 시킴으로 빨리 파일이 재생입니다 행복하게, 다음 서비스를 통해 업로드 할 때 서버에서 만든 파일을 재생할 실 거예요.
나는 그것이 정말로 벙어리 일 뿐이라고 확신하지만, 어떤 도움도 정말로 감사 할 만하다.
이 질문을 무시 코드에 대한 변경했다, 내가 직접 대답하지만, SO 늘 나 닫을 수 있도록했다. –
직접 해결 한 경우 나중에 다른 사람에게 동일한 문제가있는 경우에도 자신의 답변을 게시해야합니다. –
나는 시도했다. 그러나 그것은 내가 내가 할 수 있었던 누구나 이었어도 것에 따라 내가 이유를 놓고 갔던 대답을 게시하게하지 않을 것이다. 평판 점수와 시간 제한과 관련이있었습니다. –