예제 #1
0
        private async Task <FileStorageInfo> SaveFileContent(byte[] fileContents,
                                                             string uniqueFileName,
                                                             string format,
                                                             bool createThumbinal,
                                                             string fileFriendlyName)
        {
            if (defaultProvider == null)
            {
                throw new ArgumentException(nameof(defaultProvider) + " is null");
            }

            string fileCrc      = CalculateCRC(fileContents);
            string fileFullName = await defaultProvider.UploadFileAsync(fileContents);

            string fileThumbinalFullName = string.Empty;

            if (createThumbinal)
            {
                fileThumbinalFullName = await SimpleFileThumbinalGenerator.CreateThumbnail(defaultProvider,
                                                                                           format,
                                                                                           thumbinalConfig.Width,
                                                                                           thumbinalConfig.Height,
                                                                                           fileContents);
            }

            return(StoreFileInfo(fileContents.Length,
                                 uniqueFileName,
                                 fileCrc,
                                 fileFullName,
                                 fileThumbinalFullName,
                                 fileFriendlyName));
        }
예제 #2
0
        private async Task <FileStorageInfo> SaveFileContent(Stream stream,
                                                             string uniqueFileName,
                                                             string format,
                                                             bool createThumbinal,
                                                             string fileFriendlyName)
        {
            if (defaultProvider == null)
            {
                throw new ArgumentException(nameof(defaultProvider) + " is null");
            }

            string fileFullName = await defaultProvider.UploadFileAsync(stream);

            string thumbinalFileName = string.Empty;

            if (createThumbinal)
            {
                using (var fileStream = defaultProvider.OpenFileStream(fileFullName))
                {
                    thumbinalFileName = await SimpleFileThumbinalGenerator.CreateThumbnail(defaultProvider,
                                                                                           format,
                                                                                           thumbinalConfig.Width,
                                                                                           thumbinalConfig.Height,
                                                                                           fileStream);
                }
            }
            string fileCrc      = string.Empty;
            long   streamLength = 0;

            using (var fileStream = defaultProvider.OpenFileStream(fileFullName))
            {
                fileCrc      = CalculateCRC(fileStream);
                streamLength = stream.CanSeek ? stream.Length
                : fileStream.Length;
            }

            return(StoreFileInfo(streamLength,
                                 uniqueFileName,
                                 fileCrc,
                                 fileFullName,
                                 thumbinalFileName,
                                 fileFriendlyName));
        }