コード例 #1
0
    /// <inheritdoc />
    public async Task <FileReference> UploadFileAsync(FileContentSource fileContent)
    {
        if (fileContent == null)
        {
            throw new ArgumentNullException(nameof(fileContent));
        }

        var stream = fileContent.OpenReadStream();

        try
        {
            if (stream.Length > MAX_FILE_SIZE_MB * 1024 * 1024)
            {
                throw new ArgumentException($"Maximum supported file size is {MAX_FILE_SIZE_MB} MB.", nameof(stream));
            }

            var endpointUrl = _urlBuilder.BuildUploadFileUrl(fileContent.FileName);
            var response    = await _actionInvoker.UploadFileAsync <FileReference>(endpointUrl, stream, fileContent.ContentType);

            return(response);
        }
        finally
        {
            // Dispose the stream only in case new stream was created
            if (fileContent.CreatesNewStream)
            {
                stream.Dispose();
            }
        }
    }
コード例 #2
0
        public void BuildUploadFileUrl_ReturnsExpectedUrl()
        {
            var fileName       = "which-brewing-fits-you-1080px.jpg";
            var expectedResult = $"https://manage.kenticocloud.com/projects/{PROJECT_ID}/files/{fileName}";
            var actualResult   = _builder.BuildUploadFileUrl(fileName);

            Assert.Equal(expectedResult, actualResult);
        }