public static ChunkedUploadSession InitiateUpload(string folderId, string fileId, string fileName, long contentLength) { if (string.IsNullOrEmpty(folderId)) { folderId = null; } if (string.IsNullOrEmpty(fileId)) { fileId = null; } var file = new File { ID = fileId, FolderID = folderId, Title = fileName, ContentLength = contentLength }; using (var dao = Global.DaoFactory.GetFileDao()) { var uploadSession = dao.CreateUploadSession(file, contentLength); uploadSession.Expired = uploadSession.Created + ChunkedUploadSessionHolder.SlidingExpiration; uploadSession.Location = FilesLinkUtility.GetUploadChunkLocationUrl(uploadSession.Id, contentLength > 0); uploadSession.TenantId = CoreContext.TenantManager.GetCurrentTenant().TenantId; uploadSession.UserId = SecurityContext.CurrentAccount.ID; uploadSession.FolderId = folderId; ChunkedUploadSessionHolder.StoreSession(uploadSession); return(uploadSession); } }
public static ChunkedUploadSession UploadChunk(string uploadId, Stream stream, long chunkLength) { var uploadSession = ChunkedUploadSessionHolder.GetSession(uploadId); uploadSession.Expired = DateTime.UtcNow + ChunkedUploadSessionHolder.SlidingExpiration; if (chunkLength <= 0) { throw new Exception(FilesCommonResource.ErrorMassage_EmptyFile); } if (chunkLength > SetupInfo.ChunkUploadSize) { throw FileSizeComment.GetFileSizeException(SetupInfo.MaxUploadSize); } var maxUploadSize = GetMaxFileSize(uploadSession.FolderId, uploadSession.BytesTotal > 0); if (uploadSession.BytesUploaded + chunkLength > maxUploadSize) { AbortUpload(uploadSession); throw FileSizeComment.GetFileSizeException(maxUploadSize); } using (var dao = Global.DaoFactory.GetFileDao()) { dao.UploadChunk(uploadSession, stream, chunkLength); } if (uploadSession.BytesUploaded == uploadSession.BytesTotal) { using (var linkDao = Global.GetLinkDao()) { linkDao.DeleteAllLink(uploadSession.File.ID); } FileMarker.MarkAsNew(uploadSession.File); ChunkedUploadSessionHolder.RemoveSession(uploadSession); } else { ChunkedUploadSessionHolder.StoreSession(uploadSession); } return(uploadSession); }
public ChunkedUploadSession <T> UploadChunk <T>(string uploadId, Stream stream, long chunkLength) { var uploadSession = ChunkedUploadSessionHolder.GetSession <T>(uploadId); uploadSession.Expired = DateTime.UtcNow + ChunkedUploadSessionHolder.SlidingExpiration; if (chunkLength <= 0) { throw new Exception(FilesCommonResource.ErrorMassage_EmptyFile); } if (chunkLength > SetupInfo.ChunkUploadSize) { throw FileSizeComment.GetFileSizeException(SetupInfo.MaxUploadSize(TenantExtra, TenantStatisticsProvider)); } var maxUploadSize = GetMaxFileSize(uploadSession.FolderId, uploadSession.BytesTotal > 0); if (uploadSession.BytesUploaded + chunkLength > maxUploadSize) { AbortUpload(uploadSession); throw FileSizeComment.GetFileSizeException(maxUploadSize); } var dao = DaoFactory.GetFileDao <T>(); dao.UploadChunk(uploadSession, stream, chunkLength); if (uploadSession.BytesUploaded == uploadSession.BytesTotal) { FileMarker.MarkAsNew(uploadSession.File); ChunkedUploadSessionHolder.RemoveSession(uploadSession); } else { ChunkedUploadSessionHolder.StoreSession(uploadSession); } return(uploadSession); }
public ChunkedUploadSession <T> InitiateUpload <T>(T folderId, T fileId, string fileName, long contentLength, bool encrypted) { var file = ServiceProvider.GetService <File <T> >(); file.ID = fileId; file.FolderID = folderId; file.Title = fileName; file.ContentLength = contentLength; var dao = DaoFactory.GetFileDao <T>(); var uploadSession = dao.CreateUploadSession(file, contentLength); uploadSession.Expired = uploadSession.Created + ChunkedUploadSessionHolder.SlidingExpiration; uploadSession.Location = FilesLinkUtility.GetUploadChunkLocationUrl(uploadSession.Id); uploadSession.TenantId = TenantManager.GetCurrentTenant().TenantId; uploadSession.UserId = AuthContext.CurrentAccount.ID; uploadSession.FolderId = folderId; uploadSession.CultureName = Thread.CurrentThread.CurrentUICulture.Name; uploadSession.Encrypted = encrypted; ChunkedUploadSessionHolder.StoreSession(uploadSession); return(uploadSession); }