Box.V2.Managers.BoxFilesManager.UploadAsync C# (CSharp) Метод

UploadAsync() публичный Метод

Uploads a provided file to the target parent folder. If the file already exists, an error will be thrown. A proper timeout should be provided for large uploads.
public UploadAsync ( Box.V2.Models.BoxFileRequest fileRequest, Stream stream, List fields = null, System.TimeSpan timeout = null, byte contentMD5 = null, bool setStreamPositionToZero = true, Uri uploadUri = null ) : Task
fileRequest Box.V2.Models.BoxFileRequest BoxFileRequest object.
stream Stream Stream of uploading file.
fields List Fields which shall be returned in result.
timeout System.TimeSpan Timeout for response.
contentMD5 byte The SHA1 hash of the file.
setStreamPositionToZero bool Set position for input stream to 0.
uploadUri System.Uri Uri to use for upload. Default upload endpoint URI is used if not specified.
Результат Task
        public async Task<BoxFile> UploadAsync(BoxFileRequest fileRequest, Stream stream, List<string> fields = null,
                                                TimeSpan? timeout = null, byte[] contentMD5 = null,
                                                bool setStreamPositionToZero = true,
                                                Uri uploadUri = null)
        {
            stream.ThrowIfNull("stream");
            fileRequest.ThrowIfNull("fileRequest")
                .Name.ThrowIfNullOrWhiteSpace("filedRequest.Name");
            fileRequest.Parent.ThrowIfNull("fileRequest.Parent")
                .Id.ThrowIfNullOrWhiteSpace("fileRequest.Parent.Id");

            if (setStreamPositionToZero)
                stream.Position = 0;

            uploadUri = uploadUri == null ? _config.FilesUploadEndpointUri : uploadUri;

            BoxMultiPartRequest request = new BoxMultiPartRequest(uploadUri) { Timeout = timeout }
                .Param(ParamFields, fields)
                .FormPart(new BoxStringFormPart()
                {
                    Name = "attributes",
                    Value = _converter.Serialize(fileRequest)
                })
                .FormPart(new BoxFileFormPart()
                {
                    Name = "file",
                    Value = stream,
                    FileName = fileRequest.Name
                });

            if (contentMD5 != null)
                request.Header(Constants.RequestParameters.ContentMD5, HexStringFromBytes(contentMD5));

            IBoxResponse<BoxCollection<BoxFile>> response = await ToResponseAsync<BoxCollection<BoxFile>>(request).ConfigureAwait(false);

            // We can only upload one file at a time, so return the first entry
            return response.ResponseObject.Entries.FirstOrDefault();
        }