public virtual WebRequestStream GetRequestStreamMultiPartUpload(WebRequest request, String fileName, long fileSize)
        {
            // generate mp support
            WebRequestMultipartFormDataSupport mp = new WebRequestMultipartFormDataSupport();

            // set the right size
            fileSize = fileSize + mp.GetHeaderFooterSize(fileName);

            // set the streaming buffering
#if !WINDOWS_PHONE
            if (fileSize > 0)
            {
                // set the maximum content length size
                request.ContentLength = fileSize;
            }
#endif
            // get the stream
            WebRequestStream stream = GetRequestStream(request, fileSize);

            // prepare the stream
            mp.PrepareRequestStream(stream, fileName);

            // go ahead
            return(stream);
        }
        /// <summary>
        /// This method implements a standard multipart/form-data upload and can be overriden
        /// e.g. for WebDav upload
        /// </summary>
        /// <param name="url"></param>
        /// <param name="credentials"></param>
        /// <returns></returns>
        public virtual WebRequest CreateWebRequestMultiPartUpload(String url, ICredentials credentials)
        {
            // 1. build a valid webrequest
            WebRequest request = CreateWebRequest(url, WebRequestMethodsEx.Http.Post, credentials, false, null);

            // 2. set the request paramter
            WebRequestMultipartFormDataSupport mp = new WebRequestMultipartFormDataSupport();

            mp.PrepareWebRequest(request);

            // 3. go ahead
            return(request);
        }
예제 #3
0
        /// <summary>
        /// This method contains the routine which has to be executed when a request
        /// stream will be disposed and will be called autoamtically
        /// </summary>
        private static void DisposeWebRequestStreams(params object[] arg)
        {
            // get the params
            var request = arg[0] as WebRequest;
            var stream  = arg[1] as WebRequestStream;

            // check if we have a multipart upload
            var md = new WebRequestMultipartFormDataSupport();

            if (md.IsRequestMultiPartUpload(request))
            {
                md.FinalizeNetworkFileDataStream(stream);
            }
        }
        /// <summary>
        /// This method contains the routine which has to be executed when a request
        /// stream will be disposed and will be called autoamtically
        /// </summary>
        private void DisposeWebRequestStreams(params object[] arg)
        {
            // get the params
            WebRequest       request = arg[0] as WebRequest;
            WebRequestStream stream  = arg[1] as WebRequestStream;

            // check if we have a multipart upload
            WebRequestMultipartFormDataSupport md = new WebRequestMultipartFormDataSupport();

            if (md.IsRequestMultiPartUpload(request))
            {
                md.FinalizeNetworkFileDataStream(stream);
            }

#if WINDOWS_PHONE
            // Close Stream Bugfix for WP7
            stream.Close();
#endif
        }
        public virtual WebRequestStream GetRequestStreamMultiPartUpload(WebRequest request, String fileName, long fileSize)
        {
            // generate mp support
            WebRequestMultipartFormDataSupport mp = new WebRequestMultipartFormDataSupport();

            // set the right size
            fileSize = fileSize + mp.GetHeaderFooterSize(fileName);

            // set the streaming buffering
#if !WINDOWS_PHONE
            if (fileSize > 0)
            {                
                // set the maximum content length size
                request.ContentLength = fileSize;
            }
#endif
            // get the stream
            WebRequestStream stream = GetRequestStream(request, fileSize);

            // prepare the stream            
            mp.PrepareRequestStream(stream, fileName);

            // go ahead
            return stream;
        }
        /// <summary>
        /// This method implements a standard multipart/form-data upload and can be overriden 
        /// e.g. for WebDav upload
        /// </summary>
        /// <param name="url"></param>        
        /// <param name="credentials"></param>
        /// <returns></returns>
        public virtual WebRequest CreateWebRequestMultiPartUpload(String url, ICredentials credentials)
        {
            // 1. build a valid webrequest
            WebRequest request = CreateWebRequest(url, WebRequestMethodsEx.Http.Post, credentials, false, null);

            // 2. set the request paramter
            WebRequestMultipartFormDataSupport mp = new WebRequestMultipartFormDataSupport();
            mp.PrepareWebRequest(request);
            
            // 3. go ahead
            return request;
        }
        /// <summary>
        /// This method contains the routine which has to be executed when a request 
        /// stream will be disposed and will be called autoamtically
        /// </summary>
        private void DisposeWebRequestStreams(params object[] arg)
        {
            // get the params
            WebRequest request = arg[0] as WebRequest;
            WebRequestStream stream = arg[1] as WebRequestStream;

            // check if we have a multipart upload
            WebRequestMultipartFormDataSupport md = new WebRequestMultipartFormDataSupport();
            if (md.IsRequestMultiPartUpload(request))
                md.FinalizeNetworkFileDataStream(stream);

#if WINDOWS_PHONE 
            // Close Stream Bugfix for WP7
            stream.Close();
#endif
        }