hi joe
can you please help me as I want to upload large (100 MB) files to my server , and wanted to know how can i break it into chuncks and then put it togeather on the server to enable fast upload. does anybody have a example or code snippet for this
kindly share , here is what i am doing currently and it is taking a lot of time :
i have used Asp.net control which first copy the file to the server from where my service pick the file and encode it with the following method
public EncoderResult Encode(Video video)
{
string workingDirectory = new System.IO.FileInfo(video.RawStorageLocation).DirectoryName;
// Get the working file and directories
objCommon.VideoLog(video.VideoId, "Begin encoding process.");
string exeEncoder = "Encoder.exe";
string tmpjobFile = Path.GetTempFileName();
string tmpDir = GetTmpDir(video.VideoId);
objCommon.VideoLog(video.VideoId, String.Format("Temp file used during encoding \"{0}\"", tmpjobFile));
objCommon.VideoLog(video.VideoId, String.Format("Output directory for encoding results \"{0}\"", tmpDir));
// -- Create local dir to encode
if (!Directory.Exists(tmpDir))
Directory.CreateDirectory(tmpDir);
// -- Loading My Template job file
XmlSerializer xs = new XmlSerializer(typeof(JobFile));
JobFile jobfile = null;
using (Stream configStream = File.OpenRead(System.IO.Path.Combine(workingDirectory, "JobFile.xml")))
{
jobfile = (JobFile)xs.Deserialize(configStream);
jobfile.Job[0].OutputDirectory = tmpDir;
jobfile.Job[0].MediaFiles[0].Source = video.RawStorageLocation;
}
using (Stream configStream = File.OpenWrite(tmpjobFile))
{
xs.Serialize(configStream, jobfile);
}
video.Status = Convert.ToString(VideoStatus.Encoding);
objCommon.UpdateVideostatus(Convert.ToInt64(video.VideoId),"","","", video.Status);
objCommon.VideoLog(video.VideoId, "Encoding...");
// -- Create process start info
ProcessStartInfo psi = new ProcessStartInfo(exeEncoder);
psi.Arguments = "/JobFile \"" + tmpjobFile + "\"" + " /Log On";
psi.WorkingDirectory = ConfigurationSettings.AppSettings["MediaEncoderPath"];
//Hide MediaEncoder process window
psi.WindowStyle = ProcessWindowStyle.Hidden;
Process p = Process.Start(psi);
p.WaitForExit();
//video.Status = VideoStatus.Encoded;
//VideoBO.Update(video);
//VideoLogBO.Log(video, "Encode Complete.");
System.IO.FileInfo fileInfo = new System.IO.FileInfo(video.RawStorageLocation);
string videoPath = Path.ChangeExtension(Path.Combine(tmpDir, fileInfo.Name), ".wmv");
string thumbPath = Path.ChangeExtension(videoPath, null) + "_Thumb.jpg";
return new EncoderResult() { VideoFilePath = videoPath, ThumbFilePath = thumbPath };
}
Then it host it to the silverlight server with the follwing fucntion :
public Video AddMedia(string mediaFilePath, Video video)
{
//VideoLogBO.Log(video, "Begin Upload to Silverlight Streaming.");
objCommon.VideoLog(video.VideoId, "Begin Upload to Silverlight Streaming.");
video.Status = Convert.ToString(VideoStatus.Uploading);
objCommon.UpdateVideostatus(Convert.ToInt64(video.VideoId),"","","", video.Status);
//VideoBO.Update(video);
//Create zip file
string zipFilename = mediaFilePath + ".zip";
zipFilename = CreateSilverlightPackage(video, mediaFilePath);
//event1.WriteEntry("zipFilename" + zipFilename, EventLogEntryType.Information);
string filename = new System.IO.FileInfo(mediaFilePath).Name;
//event1.WriteEntry("Filename" + filename, EventLogEntryType.Information);
// Upload to Silverlight Streaming
objCommon.VideoLog(video.VideoId, "Uploading to Silverlight Streaming...");
//VideoLogBO.Log(video, "Uploading to Silverlight Streaming...");
string filesetName = Guid.NewGuid().ToString().Replace("-", string.Empty);
Uri silverlightStreamingUri = new Uri(string.Format("http://silverlight.services.live.com/{0}/{1}", ACCOUNTID, filesetName));
System.Net.HttpWebRequest request = System.Net.WebRequest.Create(silverlightStreamingUri) as HttpWebRequest;
request.Timeout = 20 * 60 * 1000;
request.ReadWriteTimeout = 20 * 60 * 1000;
//Note: Can't set authorization header with NetworkCredential or larger files time out
//request.Credentials = new NetworkCredential(ACCOUNTID, KEY);
byte[] userPass = System.Text.Encoding.Default.GetBytes(ACCOUNTID + ":" + KEY);
string basic = "Basic " + Convert.ToBase64String(userPass);
request.Headers["Authorization"] = basic;
request.PreAuthenticate = true;
request.ContentType = System.Net.Mime.MediaTypeNames.Application.Zip;
request.Method = WebRequestMethods.Http.Post;
using (System.IO.FileStream inputStream = new System.IO.FileStream(zipFilename, FileMode.Open))
{
using (System.IO.Stream requestStream = request.GetRequestStream())
{
CopyStream(inputStream, requestStream);
requestStream.Close();
}
}
which is very lengthy and time consuming process.
if any idea how to do that any suggestion should be apperciated please help me
pawan bali
filmjamr.com