Beispiel #1
0
        private WriteFileContextForCreationWithUpload(ContextAdapter creationContext, string fileId, bool hasData, byte preReadByte)
        {
            _responseHeaders = new Dictionary <string, string>();
            _responseStream  = new MemoryStream();
            _fileId          = fileId;

            FileContentIsAvailable = hasData;

            _context = new ContextAdapter
            {
                CancellationToken = creationContext.CancellationToken,
                Configuration     = creationContext.Configuration,
                HttpContext       = creationContext.HttpContext,
                Request           = CreateWriteFileRequest(creationContext, fileId, preReadByte),
                Response          = CreateWriteFileResponse(),
#if netfull
                OwinContext = creationContext.OwinContext
#endif
            };
        }
Beispiel #2
0
        private RequestAdapter CreateWriteFileRequest(ContextAdapter context, string fileId, byte preReadByte)
        {
            var uriBuilder = new UriBuilder(context.Request.RequestUri);

            uriBuilder.Path = uriBuilder.Path + "/" + fileId;

            var writeFileRequest = new RequestAdapter(context.Configuration.UrlPath)
            {
                Body       = new ReadOnlyStreamWithPreReadByte(context.Request.Body, preReadByte),
                Method     = context.Request.Method,
                RequestUri = uriBuilder.Uri,
                Headers    = context.Request.Headers
            };

            writeFileRequest.Headers[HeaderConstants.UploadOffset] = new List <string>(1)
            {
                "0"
            };
            writeFileRequest.Headers.Remove(HeaderConstants.UploadLength);

            return(writeFileRequest);
        }
Beispiel #3
0
        internal static async Task <WriteFileContextForCreationWithUpload> FromCreationContext(ContextAdapter creationContext, string fileId)
        {
            // Check if there is any file content available in the request.
            var buffer  = new byte[1];
            var hasData = await creationContext.Request.Body.ReadAsync(buffer, 0, 1) > 0;

            return(new WriteFileContextForCreationWithUpload(creationContext, fileId, hasData, buffer[0]));
        }