Esempio n. 1
0
        public FileStoreHandResult Save(Store.FileInfo file)
        {
            var filedetail = AsyncHelper.RunSync(() => _storageService.UploadFileFromBytesAsync(file.Bytes, new FileDetails
            {
                Name         = file.FileName,
                Size         = file.FileSize,
                AddedDate    = DateTime.Now,
                AddedBy      = "",
                Description  = file.FileName,
                Tags         = new List <string>(),
                LastModified = DateTime.Now,
                ContentType  = file.FileType
            }));

            return(new FileStoreHandResult
            {
                StoreName = this.StoreName,
                FileName = filedetail.Id,
                FileSize = file.FileSize,
                FileType = file.FileType,
                FileAddress = "",
                AddressType = AddressType.网络路径,
                Raw = new RawFileInfo {
                    Bytes = file.Bytes, FileType = file.FileType
                }
            });
        }
Esempio n. 2
0
        public FileStoreHandResult Save(Store.FileInfo file)
        {
            if (Options.LocalFolder.IsNullOrWhiteSpace())
            {
                throw new Exception("本地存储位置不能为空");
            }

            if (file.UniqueFileName.IsNullOrWhiteSpace())
            {
                var uniqueFileName = GenerateUniqueFileName(Path.GetExtension(file.FileName));
                file.UniqueFileName = uniqueFileName;
            }

            var localFolder = GetFilePath();

            // 创建文件夹
            DirectoryHelper.CreateIfNotExists(localFolder);

            var filePath = Path.Combine(localFolder, file.UniqueFileName);

            // 保存文件
            File.WriteAllBytes(filePath, file.Bytes);

            return(new FileStoreHandResult
            {
                StoreName = StoreName,
                FileName = file.UniqueFileName,
                FileAddress = filePath,
                AddressType = AddressType.本地绝对路径,
                Raw = new RawFileInfo {
                    Bytes = file.Bytes, FileType = file.FileType
                },
                FileType = file.FileType,
                FileSize = file.FileSize
            });
        }