Пример #1
0
        private async Task <bool> UploadFile(string accessToken)
        {
            if (FileUploadModel.FileHeader != null)
            {
                if (FileUploadModel.FileHeader.Id == Guid.Empty)
                {
                    var fileVer = new FileVer()
                    {
                        FileHeaderId = FileUploadModel.FileHeader.Id
                    };

                    if (string.IsNullOrWhiteSpace(FileUploadModel.URI))
                    {
                        var fileSizeSetting = await _apiHelper.GetSystemSetting(accessToken, "FILE_UPLOAD_MAX");

                        var fileExtPermitted = await _apiHelper.GetSystemSetting(accessToken, "FILE_UPLOAD_EXT");

                        var formFileContent =
                            await FileHelpers.ProcessFormFile <FileUploadModel>(
                                FileUploadModel.FormFile, ModelState, GeneralHelpers.SeperatedListToEnumerable(fileExtPermitted.Value, prefix : ".").ToArray <string>(),
                                long.Parse(fileSizeSetting.Value));

                        if (!ModelState.IsValid)
                        {
                            return(false);
                        }

                        FileUploadModel.FileHeader.FileDetail.FileExtension = Path.GetExtension(FileUploadModel.FormFile.FileName).ToLowerInvariant();
                        FileUploadModel.FileHeader.FileDetail.FileType      = FileUploadModel.FormFile.ContentType;

                        fileVer.Size          = FileUploadModel.FormFile.Length;
                        fileVer.UntrustedName = FileUploadModel.FormFile.FileName;
                        fileVer.TrustedName   = WebUtility.HtmlEncode(FileUploadModel.FormFile.FileName);
                        fileVer.Content       = formFileContent;
                    }
                    else
                    {
                        fileVer.URI = FileUploadModel.URI;
                        FileUploadModel.FileHeader.FileDetail.FileExtension = "URI";
                        FileUploadModel.FileHeader.FileDetail.FileType      = "URI";
                    }

                    FileUploadModel.FileHeader.FileLinks.Add(new FileLnk()
                    {
                        LinkId       = FileUploadModel.linkId,
                        LinkType     = FileUploadModel.linkType,
                        FileHeaderId = FileUploadModel.FileHeader.Id
                    });

                    FileUploadModel.FileHeader.FileVersions.Add(fileVer);
                }
            }

            return(await CreateOrUpdateFileAsync(accessToken));
        }
Пример #2
0
        private async Task <bool> UploadFile(string accessToken)
        {
            if (FileVersionUploadModel.FileVersion != null)
            {
                if (FileVersionUploadModel.FileVersion.Id == Guid.Empty)
                {
                    if (string.IsNullOrWhiteSpace(FileVersionUploadModel.URI))
                    {
                        var fileSizeSetting = await _apiHelper.GetSystemSetting(accessToken, "FILE_UPLOAD_MAX");

                        var fileExtPermitted = await _apiHelper.GetSystemSetting(accessToken, "FILE_UPLOAD_EXT");

                        var formFileContent =
                            await FileHelpers.ProcessFormFile <FileUploadModel>(
                                FileVersionUploadModel.FormFile, ModelState, GeneralHelpers.SeperatedListToEnumerable(fileExtPermitted.Value, prefix : ".").ToArray <string>(),
                                long.Parse(fileSizeSetting.Value));

                        if (!ModelState.IsValid)
                        {
                            return(false);
                        }

                        FileVersionUploadModel.FileVersion.Size          = FileVersionUploadModel.FormFile.Length;
                        FileVersionUploadModel.FileVersion.UntrustedName = FileVersionUploadModel.FormFile.FileName;
                        FileVersionUploadModel.FileVersion.TrustedName   = WebUtility.HtmlEncode(FileVersionUploadModel.FormFile.FileName);
                        FileVersionUploadModel.FileVersion.Content       = formFileContent;
                    }
                    else
                    {
                        FileVersionUploadModel.FileVersion.URI = FileVersionUploadModel.URI;
                    }
                }
            }

            return(await CreateFileVersionAsync(accessToken));
        }