示例#1
0
        public FileUploadStatus UploadBlock(int id, byte[] chunk, FileUploadModel modelObj)
        {
            FileSysFileUploadModel model = modelObj as FileSysFileUploadModel;

            if (model != null && model.File != null)
            {
                if (chunk.Length > 0)
                {
                    model.File.Seek(id * model.BlockSize, SeekOrigin.Begin);
                    model.File.Write(chunk, 0, chunk.Length);
                }

                if (id == model.BlockCount)
                {
                    model.File.Dispose();
                    return(new FileUploadStatus()
                    {
                        Error = false, IsLastBlock = true
                    });
                }
            }

            return(new FileUploadStatus()
            {
                Error = false, IsLastBlock = false
            });
        }
示例#2
0
        public FileUploadModel PrepareMetaData(int blocksCount, int blockSize, string fileName, long fileSize)
        {
            FileInfo fi = new FileInfo(getFullPath(fileName));

            Directory.CreateDirectory(fi.DirectoryName);
            FileStream fs           = fi.Create();
            var        fileToUpload = new FileSysFileUploadModel()
            {
                BlockCount          = blocksCount,
                FileName            = fileName,
                FileSize            = fileSize,
                StartTime           = DateTime.Now,
                IsUploadCompleted   = false,
                UploadStatusMessage = string.Empty,
                BlockSize           = blockSize,
                File = fs
            };

            return(fileToUpload);
        }