// (c) Copyright Ascensio System SIA 2010-2022 // // This program is a free software product. // You can redistribute it and/or modify it under the terms // of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software // Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended // to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of // any third-party rights. // // This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see // the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html // // You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021. // // The interactive user interfaces in modified source and object code versions of the Program must // display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3. // // Pursuant to Section 7(b) of the License you must retain the original Product logo when // distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under // trademark law for use of our trademarks. // // All the Product's GUI elements, including illustrations and icon sets, as well as technical writing // content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 // International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode namespace ASC.Files.Api; [ConstraintRoute("int")] public class UploadControllerInternal : UploadController { public UploadControllerInternal( UploadControllerHelper filesControllerHelper, FolderDtoHelper folderDtoHelper, FileDtoHelper fileDtoHelper) : base(filesControllerHelper, folderDtoHelper, fileDtoHelper) { } } public class UploadControllerThirdparty : UploadController { public UploadControllerThirdparty( UploadControllerHelper filesControllerHelper, FolderDtoHelper folderDtoHelper, FileDtoHelper fileDtoHelper) : base(filesControllerHelper, folderDtoHelper, fileDtoHelper) { } } public abstract class UploadController : ApiControllerBase { private readonly UploadControllerHelper _filesControllerHelper; public UploadController(UploadControllerHelper filesControllerHelper, FolderDtoHelper folderDtoHelper, FileDtoHelper fileDtoHelper) : base(folderDtoHelper, fileDtoHelper) { _filesControllerHelper = filesControllerHelper; } /// /// 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
  • /// /// ]]> ///
    [HttpPost("{folderId}/upload/create_session")] public Task CreateUploadSessionAsync(T folderId, SessionRequestDto inDto) { return _filesControllerHelper.CreateUploadSessionAsync(folderId, inDto.FileName, inDto.FileSize, inDto.RelativePath, inDto.Encrypted, inDto.CreateOn); } [HttpPost("file/{fileId}/edit_session")] public Task CreateEditSession(T fileId, long fileSize) { return _filesControllerHelper.CreateEditSession(fileId, fileSize); } /// /// 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 /// [HttpPost("{folderId}/insert", Order = 1)] public Task> InsertFileAsync(T folderId, [FromForm][ModelBinder(BinderType = typeof(InsertFileModelBinder))] InsertFileRequestDto inDto) { return _filesControllerHelper.InsertFileAsync(folderId, inDto.Stream, inDto.Title, inDto.CreateNewIfExist, inDto.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 [HttpPost("{folderId}/upload", Order = 1)] public Task UploadFileAsync(T folderId, [ModelBinder(BinderType = typeof(UploadModelBinder))] UploadRequestDto inDto) { return _filesControllerHelper.UploadFileAsync(folderId, inDto); } } public class UploadControllerCommon : ApiControllerBase { private readonly GlobalFolderHelper _globalFolderHelper; private readonly UploadControllerHelper _filesControllerHelper; public UploadControllerCommon( GlobalFolderHelper globalFolderHelper, UploadControllerHelper filesControllerHelper, FolderDtoHelper folderDtoHelper, FileDtoHelper fileDtoHelper) : base(folderDtoHelper, fileDtoHelper) { _globalFolderHelper = globalFolderHelper; _filesControllerHelper = filesControllerHelper; } /// /// 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 /// [HttpPost("@common/insert")] public async Task> InsertFileToCommonFromBodyAsync([FromForm][ModelBinder(BinderType = typeof(InsertFileModelBinder))] InsertFileRequestDto inDto) { return await _filesControllerHelper.InsertFileAsync(await _globalFolderHelper.FolderCommonAsync, inDto.Stream, inDto.Title, inDto.CreateNewIfExist, inDto.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 /// [HttpPost("@my/insert")] public Task> InsertFileToMyFromBodyAsync([FromForm][ModelBinder(BinderType = typeof(InsertFileModelBinder))] InsertFileRequestDto inDto) { return _filesControllerHelper.InsertFileAsync(_globalFolderHelper.FolderMy, inDto.Stream, inDto.Title, inDto.CreateNewIfExist, inDto.KeepConvertStatus); } /// /// 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 [HttpPost("@common/upload")] public async Task UploadFileToCommonAsync([ModelBinder(BinderType = typeof(UploadModelBinder))] UploadRequestDto inDto) { inDto.CreateNewIfExist = false; return await _filesControllerHelper.UploadFileAsync(await _globalFolderHelper.FolderCommonAsync, inDto); } /// /// 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 [HttpPost("@my/upload")] public Task UploadFileToMyAsync([ModelBinder(BinderType = typeof(UploadModelBinder))] UploadRequestDto inDto) { inDto.CreateNewIfExist = false; return _filesControllerHelper.UploadFileAsync(_globalFolderHelper.FolderMy, inDto); } }