public void BeginUpload()
        {
            try
            {
                request = (HttpWebRequest)WebRequest.Create(uri);

                request.Method = "PUT";
                request.Headers["x-ms-blob-type"] = "BlockBlob";
                request.ContentType = MimeTypeMapper.GetMimeType(attachment.FileReference.Path);

                StartTimer();

                request.BeginGetRequestStream(new AsyncCallback(AddRequestData), null);
            }
            catch (Exception e)
            {
                OnFailed(e, RetryStrategy.Never);
            }
        }
Example #2
0
        private string GetMultipartHeader()
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendFormat("--{0}\r\n", boundary);
            builder.AppendFormat("{0}\r\n", GetContentDisposition());

            if (string.IsNullOrEmpty(formPartContentType))
            {
                if (!string.IsNullOrEmpty(formPartFilename))
                {
                    builder.AppendFormat("Content-Type: {0}\r\n", MimeTypeMapper.GetMimeType(formPartFilename));
                }
            }
            else
            {
                builder.AppendFormat("Content-Type: {0}\r\n", formPartContentType);
            }

            builder.AppendFormat("\r\n");

            return(builder.ToString());
        }
        private static void MatchContentTypeToFileName(string fileName, string givenContentType, string[] allowedContentTypes, Dictionary <FileCheckLayers, bool> layers, bool foundAllLayers)
        {
            var extention = "";

            if (!string.IsNullOrWhiteSpace(fileName))
            {
                var splittedName = fileName.Split(".");
                extention = splittedName[splittedName.Length - 1];
            }

            var expectedContentType = MimeTypeMapper.GetMimeType(extention);

            if (!string.IsNullOrWhiteSpace(expectedContentType) && !expectedContentType.Split(',').ToList().Any(a => a.Equals(givenContentType, StringComparison.InvariantCultureIgnoreCase)))
            {
                throw new BusinessException(string.Format($"Content-type of the file name {expectedContentType} does not match the content-type of the given file {givenContentType}."), ErrorType.ContentTypeToExtensionMismatch);
            }

            bool foundCheckContentType = layers.TryGetValue(FileCheckLayers.CheckContentType, out foundCheckContentType);

            if (foundCheckContentType || foundAllLayers)
            {
                IsContentTypeAllowed(expectedContentType, allowedContentTypes);
            }
        }
 // Token: 0x060078D2 RID: 30930 RVA: 0x002266E9 File Offset: 0x002248E9
 protected override string GetContentTypeCore()
 {
     return(MimeTypeMapper.GetMimeTypeFromUri(new Uri(base.Uri.ToString(), UriKind.RelativeOrAbsolute)).ToString());
 }
 // Token: 0x06007A5A RID: 31322 RVA: 0x0022ABA9 File Offset: 0x00228DA9
 protected override string GetContentTypeCore()
 {
     this.EnsureResourceLocationSet();
     return(MimeTypeMapper.GetMimeTypeFromUri(new Uri(this._name, UriKind.RelativeOrAbsolute)).ToString());
 }