public void UploadFileEx()
{
ErrorCode = Constants.NoError;
ErrorDescr = "";
try
{
if (currentChunkStartPos == 0 && currentChunkEndPos == 0) // first chunk upload
{
CalcNextChunkRanges();
}
UriBuilder ub = new UriBuilder(UploadUrl);
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(ub.Uri);
webrequest.Method = "POST";
webrequest.ContentType = "application/octet-stream";
// Some russian letters in filename lead to exception, so we do uri encode on client side
// and uri decode on server side
webrequest.Headers["Content-Disposition"] = "attachment; filename=\"" + HttpUtility.UrlEncode(File.Name) + "\"";
webrequest.Headers["X-Content-Range"] = "bytes " + currentChunkStartPos + "-" + currentChunkEndPos + "/" + FileLength;
webrequest.Headers["Session-ID"] = SessionId;
webrequest.BeginGetRequestStream(new AsyncCallback(WriteCallback), webrequest);
}
catch (WebException ex)
{
ErrorCode = Constants.HttpError;
setErrorDescription(ex, "Ex1");
}
catch (IOException ex)
{
ErrorCode = Constants.IOError;
setErrorDescription(ex, "Ex1");
}
catch (Exception ex)
{
ErrorCode = Constants.OtherError;
setErrorDescription(ex, "Ex1");
}
if (ErrorCode != Constants.NoError)
{
SetFileStatus();
}
}