コード例 #1
0
        public FileUploadResult ProcessUpload(HttpContext context)
        {
            var fileUploadResult = new FileUploadResult();

            if (!ProgressFileUploader.HasFilesToUpload(context)) return fileUploadResult;

            var file = new ProgressFileUploader.FileToUpload(context);

            if (String.IsNullOrEmpty(file.FileName) || file.ContentLength == 0)
                throw new InvalidOperationException("Invalid file.");

            if (0 < SetupInfo.MaxImageUploadSize && SetupInfo.MaxImageUploadSize < file.ContentLength)
            {
                fileUploadResult.Success = false;
                fileUploadResult.Message = FileSizeComment.GetFileImageSizeNote(CRMCommonResource.ErrorMessage_UploadFileSize,false).HtmlEncode();
                return fileUploadResult;
            }

            if (FileUtility.GetFileTypeByFileName(file.FileName) != FileType.Image) {
                    fileUploadResult.Success = false;
                    fileUploadResult.Message = CRMJSResource.ErrorMessage_NotImageSupportFormat.HtmlEncode();
                    return fileUploadResult;
            }


            var contactId = Convert.ToInt32(context.Request["contactID"]);
            var uploadOnly = Convert.ToBoolean(context.Request["uploadOnly"]);
            var tmpDirName = Convert.ToString(context.Request["tmpDirName"]);
            var photoUri = "";

            if (contactId != 0)
            {
                photoUri = ContactPhotoManager.UploadPhoto(file.InputStream, contactId, uploadOnly);
            }
            else
            {
                if (String.IsNullOrEmpty(tmpDirName))
                {
                    tmpDirName = Guid.NewGuid().ToString();
                }
                photoUri = ContactPhotoManager.UploadPhoto(file.InputStream, tmpDirName);
            }
            fileUploadResult.Success = true;
            fileUploadResult.Data = photoUri;

            return fileUploadResult;
        }
コード例 #2
0
        public override FileUploadResult ProcessUpload(HttpContext context)
        {
            var fileUploadResult = new FileUploadResult();

            if (!ProgressFileUploader.HasFilesToUpload(context)) return fileUploadResult;

            var file = new ProgressFileUploader.FileToUpload(context);

            if (String.IsNullOrEmpty(file.FileName) || file.ContentLength == 0)
                throw new InvalidOperationException("Invalid file.");

            if (0 < SetupInfo.MaxUploadSize && SetupInfo.MaxUploadSize < file.ContentLength)
                throw FileSizeComment.FileSizeException;

            if (CallContext.GetData("CURRENT_ACCOUNT") == null)
                CallContext.SetData("CURRENT_ACCOUNT", new Guid(context.Request["UserID"]));


            var fileName = file.FileName.LastIndexOf('\\') != -1
                               ? file.FileName.Substring(file.FileName.LastIndexOf('\\') + 1)
                               : file.FileName;

            var document = new File
                {
                    Title = fileName,
                    FolderID = Global.DaoFactory.GetFileDao().GetRoot(),
                    ContentLength = file.ContentLength
                };

            document = Global.DaoFactory.GetFileDao().SaveFile(document, file.InputStream);

            fileUploadResult.Data = document.ID;
            fileUploadResult.FileName = document.Title;
            fileUploadResult.FileURL = document.FileDownloadUrl;


            fileUploadResult.Success = true;


            return fileUploadResult;
        }
コード例 #3
0
        public FileUploadResult ProcessUpload(HttpContext context)
        {
            var fileUploadResult = new FileUploadResult();

            if (!ProgressFileUploader.HasFilesToUpload(context)) return fileUploadResult;

            var file = new ProgressFileUploader.FileToUpload(context);

            String assignedPath;

            Global.GetStore().SaveTemp("temp", out assignedPath, file.InputStream);

            file.InputStream.Position = 0;

            var jObject = ImportFromCSV.GetInfo(file.InputStream, context.Request["importSettings"]);

            jObject.Add("assignedPath", assignedPath);

            fileUploadResult.Success = true;
            fileUploadResult.Data = Convert.ToBase64String(Encoding.UTF8.GetBytes(jObject.ToString()));

            return fileUploadResult;
        }
コード例 #4
0
        public override FileUploadResult ProcessUpload(HttpContext context)
        {
            var file_name = string.Empty;
            MailAttachment attachment = null;
            try
            {
                if (!SecurityContext.AuthenticateMe(CookiesManager.GetCookies(CookiesType.AuthKey)))
                    throw new UnauthorizedAccessException(MailResource.AttachemntsUnauthorizedError);

                if (ProgressFileUploader.HasFilesToUpload(context))
                {
                    try
                    {
                        var stream_id = context.Request["stream"];
                        var mail_id = Convert.ToInt32(context.Request["messageId"]);

                        if (mail_id < 1)
                            throw new AttachmentsException(AttachmentsException.Types.MESSAGE_NOT_FOUND,
                                                           "Message not yet saved!");

                        if (String.IsNullOrEmpty(stream_id))
                            throw new AttachmentsException(AttachmentsException.Types.BAD_PARAMS, "Have no stream");

                        var posted_file = new ProgressFileUploader.FileToUpload(context);

                        file_name = context.Request["name"];

                        attachment = new MailAttachment
                            {
                                fileId = -1,
                                size = posted_file.ContentLength,
                                fileName = file_name,
                                streamId = stream_id,
                                tenant = TenantId,
                                user = Username
                            };

                        attachment = _mailBoxManager.AttachFile(TenantId, Username, mail_id,
                                                                    file_name, posted_file.InputStream, stream_id);

                        return new FileUploadResult
                            {
                                Success = true,
                                FileName = attachment.fileName,
                                FileURL = attachment.storedFileUrl,
                                Data = attachment
                            };
                    }
                    catch (AttachmentsException e)
                    {
                        string error_message;

                        switch (e.ErrorType)
                        {
                            case AttachmentsException.Types.BAD_PARAMS:
                                error_message = MailScriptResource.AttachmentsBadInputParamsError;
                                break;
                            case AttachmentsException.Types.EMPTY_FILE:
                                error_message = MailScriptResource.AttachmentsEmptyFileNotSupportedError;
                                break;
                            case AttachmentsException.Types.MESSAGE_NOT_FOUND:
                                error_message = MailScriptResource.AttachmentsMessageNotFoundError;
                                break;
                            case AttachmentsException.Types.TOTAL_SIZE_EXCEEDED:
                                error_message = MailScriptResource.AttachmentsTotalLimitError;
                                break;
                            case AttachmentsException.Types.DOCUMENT_NOT_FOUND:
                                error_message = MailScriptResource.AttachmentsDocumentNotFoundError;
                                break;
                            case AttachmentsException.Types.DOCUMENT_ACCESS_DENIED:
                                error_message = MailScriptResource.AttachmentsDocumentAccessDeniedError;
                                break;
                            default:
                                error_message = MailScriptResource.AttachmentsUnknownError;
                                break;
                        }
                        throw new Exception(error_message);
                    }
                    catch (ASC.Core.Tenants.TenantQuotaException)
                    {
                        throw;
                    }
                    catch (Exception)
                    {
                        throw new Exception(MailScriptResource.AttachmentsUnknownError);
                    }
                }
                throw new Exception(MailScriptResource.AttachmentsBadInputParamsError);
            }
            catch (Exception ex)
            {
                return new FileUploadResult
                    {
                        Success = false,
                        FileName = file_name,
                        Data = attachment,
                        Message = ex.Message,
                    };
            }
        }