namespace ASC.Files.Api; public class UploadController : ApiControllerBase { private readonly GlobalFolderHelper _globalFolderHelper; public UploadController( FilesControllerHelper filesControllerHelperInt, FilesControllerHelper filesControllerHelperString, GlobalFolderHelper globalFolderHelper) : base(filesControllerHelperInt, filesControllerHelperString) { _globalFolderHelper = globalFolderHelper; } /// /// Creates session to upload large files in multiple chunks. /// /// Chunked upload /// Uploads /// Id of the folder in which file will be uploaded /// Name of file which has to be uploaded /// Length in bytes of file which has to be uploaded /// Relative folder from folderId /// /// /// 512 and greater or equal than 10 mb. Last chunk can have any size. /// After initial request respond with status 200 OK you must obtain value of 'location' field from the response. Send all your chunks to that location. /// Each chunk must be sent in strict order in which chunks appears in file. /// After receiving each chunk if no errors occured server will respond with current information about upload session. /// When number of uploaded bytes equal to the number of bytes you send in initial request server will respond with 201 Created and will send you info about uploaded file. /// ]]> /// /// /// ///
  • id: unique id of this upload session
  • ///
  • created: UTC time when session was created
  • ///
  • expired: UTC time when session will be expired if no chunks will be sent until that time
  • ///
  • location: URL to which you must send your next chunk
  • ///
  • bytes_uploaded: If exists contains number of bytes uploaded for specific upload id
  • ///
  • bytes_total: Number of bytes which has to be uploaded
  • /// /// ]]> ///
    [Create("{folderId}/upload/create_session")] public Task CreateUploadSessionFromBodyAsync(string folderId, [FromBody] SessionModel sessionModel) { return _filesControllerHelperString.CreateUploadSessionAsync(folderId, sessionModel.FileName, sessionModel.FileSize, sessionModel.RelativePath, sessionModel.LastModified, sessionModel.Encrypted); } [Create("{folderId:int}/upload/create_session")] public Task CreateUploadSessionFromBodyAsync(int folderId, [FromBody] SessionModel sessionModel) { return _filesControllerHelperInt.CreateUploadSessionAsync(folderId, sessionModel.FileName, sessionModel.FileSize, sessionModel.RelativePath, sessionModel.LastModified, sessionModel.Encrypted); } [Create("{folderId}/upload/create_session")] [Consumes("application/x-www-form-urlencoded")] public Task CreateUploadSessionFromFormAsync(string folderId, [FromForm] SessionModel sessionModel) { return _filesControllerHelperString.CreateUploadSessionAsync(folderId, sessionModel.FileName, sessionModel.FileSize, sessionModel.RelativePath, sessionModel.LastModified, sessionModel.Encrypted); } [Create("{folderId:int}/upload/create_session")] [Consumes("application/x-www-form-urlencoded")] public Task CreateUploadSessionFromFormAsync(int folderId, [FromForm] SessionModel sessionModel) { return _filesControllerHelperInt.CreateUploadSessionAsync(folderId, sessionModel.FileName, sessionModel.FileSize, sessionModel.RelativePath, sessionModel.LastModified, sessionModel.Encrypted); } /// /// Uploads the file specified with single file upload /// /// Folder ID to upload to /// Request Input stream /// Name of file which has to be uploaded /// Create New If Exist /// Keep status conversation after finishing /// Uploads /// [Create("{folderId}/insert", order: int.MaxValue)] public Task> InsertFileAsync(string folderId, [FromForm][ModelBinder(BinderType = typeof(InsertFileModelBinder))] InsertFileModel model) { return _filesControllerHelperString.InsertFileAsync(folderId, model.Stream, model.Title, model.CreateNewIfExist, model.KeepConvertStatus); } [Create("{folderId:int}/insert", order: int.MaxValue - 1)] public Task> InsertFileFromFormAsync(int folderId, [FromForm][ModelBinder(BinderType = typeof(InsertFileModelBinder))] InsertFileModel model) { return _filesControllerHelperInt.InsertFileAsync(folderId, model.Stream, model.Title, model.CreateNewIfExist, model.KeepConvertStatus); } /// /// Uploads the file specified with single file upload to 'Common Documents' section /// /// Request Input stream /// Name of file which has to be uploaded /// Create New If Exist /// Keep status conversation after finishing /// Uploads /// [Create("@common/insert")] public async Task> InsertFileToCommonFromBodyAsync([FromForm][ModelBinder(BinderType = typeof(InsertFileModelBinder))] InsertFileModel model) { return await _filesControllerHelperInt.InsertFileAsync(await _globalFolderHelper.FolderCommonAsync, model.Stream, model.Title, model.CreateNewIfExist, model.KeepConvertStatus); } /// /// Uploads the file specified with single file upload to 'Common Documents' section /// /// Request Input stream /// Name of file which has to be uploaded /// Create New If Exist /// Keep status conversation after finishing /// Uploads /// [Create("@my/insert")] public Task> InsertFileToMyFromBodyAsync([FromForm][ModelBinder(BinderType = typeof(InsertFileModelBinder))] InsertFileModel model) { return _filesControllerHelperInt.InsertFileAsync(_globalFolderHelper.FolderMy, model.Stream, model.Title, model.CreateNewIfExist, model.KeepConvertStatus); } /// /// Uploads the file specified with single file upload or standart multipart/form-data method to the selected folder /// /// Upload to folder /// Uploads /// /// ///
  • Single file upload. You should set Content-Type & Content-Disposition header to specify filename and content type, and send file in request body
  • ///
  • Using standart multipart/form-data method
  • /// ]]> ///
    /// Folder ID to upload to /// Request Input stream /// Content-Type Header /// Content-Disposition Header /// List of files when posted as multipart/form-data /// Create New If Exist /// If True, upload documents in original formats as well /// Keep status conversation after finishing /// Uploaded file [Create("{folderId}/upload", order: int.MaxValue)] public Task UploadFileAsync(string folderId, [ModelBinder(BinderType = typeof(UploadModelBinder))] UploadModel uploadModel) { return _filesControllerHelperString.UploadFileAsync(folderId, uploadModel); } [Create("{folderId:int}/upload", order: int.MaxValue - 1)] public Task UploadFileAsync(int folderId, [ModelBinder(BinderType = typeof(UploadModelBinder))] UploadModel uploadModel) { return _filesControllerHelperInt.UploadFileAsync(folderId, uploadModel); } /// /// Uploads the file specified with single file upload or standart multipart/form-data method to 'Common Documents' section /// /// Upload to Common /// Uploads /// /// ///
  • Single file upload. You should set Content-Type & Content-Disposition header to specify filename and content type, and send file in request body
  • ///
  • Using standart multipart/form-data method
  • /// ]]> ///
    /// Request Input stream /// Content-Type Header /// Content-Disposition Header /// List of files when posted as multipart/form-data /// Uploaded file [Create("@common/upload")] public async Task UploadFileToCommonAsync([ModelBinder(BinderType = typeof(UploadModelBinder))] UploadModel uploadModel) { uploadModel.CreateNewIfExist = false; return await _filesControllerHelperInt.UploadFileAsync(await _globalFolderHelper.FolderCommonAsync, uploadModel); } /// /// Uploads the file specified with single file upload or standart multipart/form-data method to 'My Documents' section /// /// Upload to My /// Uploads /// /// ///
  • Single file upload. You should set Content-Type & Content-Disposition header to specify filename and content type, and send file in request body
  • ///
  • Using standart multipart/form-data method
  • /// ]]> ///
    /// Request Input stream /// Content-Type Header /// Content-Disposition Header /// List of files when posted as multipart/form-data /// Uploaded file [Create("@my/upload")] public Task UploadFileToMyAsync([ModelBinder(BinderType = typeof(UploadModelBinder))] UploadModel uploadModel) { uploadModel.CreateNewIfExist = false; return _filesControllerHelperInt.UploadFileAsync(_globalFolderHelper.FolderMy, uploadModel); } }