Example #1
0
        public override Network.RequestBody GetRequestBody()
        {
            RequestBody body = null;

            if (srcPath != null)
            {
                FileInfo fileInfo = new FileInfo(srcPath);

                if (contentLength == -1 || contentLength + fileOffset > fileInfo.Length)
                {
                    contentLength = fileInfo.Length - fileOffset;
                }

                body = new FileRequestBody(srcPath, fileOffset, contentLength);
                body.ProgressCallback = progressCallback;
            }
            else
            if (data != null)
            {
                body = new ByteRequestBody(data);
                body.ProgressCallback = progressCallback;
            }

            return(body);
        }
Example #2
0
        public override Network.RequestBody GetRequestBody()
        {
            RequestBody body = null;

            if (srcPath != null)
            {
                FileInfo fileInfo = new FileInfo(srcPath);

                if (contentLength == -1 || contentLength + fileOffset > fileInfo.Length)
                {
                    contentLength = fileInfo.Length - fileOffset;
                }

                body = new FileRequestBody(srcPath, fileOffset, contentLength);
                body.ProgressCallback = progressCallback;
            }
            else if (data != null)
            {
                body = new ByteRequestBody(data);
                body.ProgressCallback = progressCallback;
            }
            else if (stream != null)
            {
                if (fileOffset < 0)
                {
                    fileOffset = 0L;
                }
                if (contentLength == -1L)
                {
                    contentLength = stream.Length - fileOffset;
                }
                if (fileOffset + contentLength > stream.Length)
                {
                    throw new CosException.CosClientException(
                              (int)COSXML.Common.CosClientError.InvalidArgument,
                              "stream offset + contentLength greater than stream.Length");
                }
                body = new StreamRequestBody(stream, fileOffset, contentLength);
            }

            return(body);
        }