Exemplo n.º 1
0
        UploadedFile CreateUploadedFile(NameValueCollection headers)
        {
            string contentDisposition = headers["content-disposition"];

            if (contentDisposition != null)
            {
                string[] dispositionParts = MimeHelper.QuotedSemiSplit(contentDisposition);

                if (dispositionParts.Length > 2)
                {
                    string fileName = MimeHelper.GetParts(dispositionParts[2], '=')[1];

                    if (fileName != "\"\"")
                    {
                        fileName = fileName.Replace("\"", string.Empty);

                        string sourceElement = MimeHelper.GetParts(dispositionParts[1], '=')[1].Replace("\"", string.Empty);

                        UploadedFile file = new UploadedFile(fileName, headers["content-type"], sourceElement, _request, _httpRequest);

                        return(file);
                    }
                }
            }

            return(null);
        }
Exemplo n.º 2
0
        /*UploadSettings LoadUploadSettings(string textParts)
         * {
         *  // TODO: parse text parts for settings
         * }*/

        public void BeginPart(NameValueCollection headers)
        {
            // Create a part for the file, or null if this isn't a valid file
            if (headers != null)
            {
                _currentFile = CreateUploadedFile(headers);
            }
            else
            {
                _currentFile = CreateSingleUploadedFile();
            }

            if (_currentFile != null)
            {
                //if (UploadSettings == null)
                //    LoadUploadSettings(_textParts.ToString());

                //SimpleLogger.Log("Starting file part", _uploadStatus.UploadId);
                //SimpleLogger.Log(_currentFile, _uploadStatus.UploadId);

                // Create a stream for the file
                if (_request.UploadFilter == null || _request.UploadFilter.ShouldHandleFile(_httpRequest, _currentFile))
                {
                    _currentStream = _request.UploadStreamProvider.GetWriteStream(_currentFile);
                }
                else
                {
                    _currentStream = Stream.Null;
                }

                _fileLength = 0;

                _request._uploadedFilesInternal.Add(_currentFile);

                SlickUploadContext.UpdateRequest(_request, true);
            }
            else
            {
                //SimpleLogger.Log("Starting non-file part", _uploadStatus.UploadId);

                // Write out the boundary start
                _textParts.Append(_httpRequest.ContentEncoding.GetString(_boundary) + "\r\n");

                // Write out the headers as textparts
                for (int i = 0; i < headers.Count; i++)
                {
                    _textParts.Append(headers.Keys[i] + ": " + headers[i] + "\r\n");
                }

                _textParts.Append("\r\n");

                // Add to our form collection
                string contentDisposition = headers["content-disposition"];

                if (contentDisposition != null)
                {
                    string[] dispositionParts = MimeHelper.QuotedSemiSplit(contentDisposition);

                    if (dispositionParts.Length == 2 && dispositionParts[1].Trim().StartsWith("name="))
                    {
                        _httpRequest.Form.Add(MimeHelper.GetParts(dispositionParts[1], '=')[1].Replace("\"", string.Empty), null);
                    }
                }
            }
        }