public IActionResult AddFile(string type = "Image")
        {
            if (!UserInfo.isLoggedIn)
            {
                return(RedirectToAction("Login", "Home"));
            }
            FileUploadObject file = new FileUploadObject();

            file.Type = type;
            return(View(file));
        }
Example #2
0
        internal async Task <IList <FileUploadObject> > UploadFiles(IList <string> filePaths, string processId, string jobName, IProgress <string> progress = null)
        {
            var remotePaths = new List <FileUploadObject>();

            foreach (var filePath in filePaths)
            {
                var fileUploadUri = new Uri(baseUri, $"files/{processId}/{jobName}/{Path.GetFileName(filePath)}");

                FileUploadObject generatedRemotePath = null;
                await DoWithClientAsync(fileUploadUri, async client =>
                {
                    var cloudPath       = await client.UploadStringTaskAsync(fileUploadUri, "");
                    generatedRemotePath = JsonConvert.DeserializeObject <FileUploadObject>(cloudPath);
                });

                remotePaths.Add(generatedRemotePath);
                progress?.Report($"Uploading {Path.GetFileName(filePath)} to {generatedRemotePath.RemotePath}");

                await Task.Run(() =>
                {
                    using (var stream = File.Open(filePath, FileMode.Open))
                    {
                        var files = new[]
                        {
                            new UploadFile
                            {
                                Name        = "file",
                                Filename    = Path.GetFileName(filePath),
                                ContentType = "text/plain",
                                Stream      = stream
                            }
                        };

                        var values = new NameValueCollection();
                        foreach (var field in generatedRemotePath.Fields)
                        {
                            values.Add(field.Key, field.Value);
                        }

                        FileHelper.UploadFiles(generatedRemotePath.Url, files, values);
                    }
                });
            }

            return(remotePaths);
        }
        async void HandleUploadImageClicked(object sender, System.EventArgs e)
        {
            if (await VerifyPrivilagesOrPropmtToLogInAsync(viewModel.Item))
            {
                var config = new StoreCameraMediaOptions()
                {
                    DefaultCamera = CameraDevice.Rear
                };

                MediaFile photo = null;
                try
                {
                    photo = await CrossMedia.Current.TakePhotoAsync(config);
                } catch (Exception ex)
                {
                    HandleException(ex);
                }


                if (photo != null)
                {
                    var s    = photo.GetStream();
                    var data = CdbApiFactory.ConvertStreamDataToBase64(s);
                    var file = new FileUploadObject
                    {
                        FileName     = "Mobile-Image.jpg",
                        Base64Binary = data
                    };

                    //var stream = new MemoryStream(bytes);
                    var itemApi = CdbApiFactory.Instance.itemApi;
                    try
                    {
                        var itemId = viewModel.Item.Id;
                        await itemApi.UploadImageForItemAsync(itemId, file);

                        var newItem = itemApi.GetItemById(itemId);
                        updateItem(newItem);
                    }
                    catch (Exception ex)
                    {
                        HandleException(ex);
                    }
                }
            }
        }
        public async Task <IActionResult> AddFile(FileUploadObject test)
        {
            if (!UserInfo.isLoggedIn)
            {
                return(RedirectToAction("Login", "Home"));
            }
            if (ModelState.IsValid)
            {
                using (var memoryStream = new MemoryStream())
                {
                    await test.URL.CopyToAsync(memoryStream);

                    if (memoryStream.Length < 2097152)
                    {
                        var extension = Path.GetExtension(test.URL.FileName).ToLower();
                        if ((extension.Equals(".png") && test.Type.Equals("Image")) || (extension.Equals(".pdf") && test.Type.Equals("Resume")))
                        {
                            var FileKey    = UserInfo.UserID.ToString() + extension;
                            var BucketName = test.Type.Equals("Image") ? SD.BucketName + @"/" + SD.ProfileImageFolder : SD.BucketName + @"/" + SD.ResumeFolder;
                            var response   = await _service.UploadFileAsync(memoryStream, BucketName, FileKey);

                            if (response.UploadSuccessful)
                            {
                                return(RedirectToAction(nameof(Index), "Profile"));
                            }
                            else
                            {
                                return(Ok(response));
                            }
                        }
                        else
                        {
                            ModelState.AddModelError("url", "Extension must be png / pdf");
                            return(View(test));
                        }
                    }

                    ModelState.AddModelError("url", "File must be less than 2 mb");
                }
            }
            return(View(test));
        }
        /// <summary>
        /// Save a file.
        /// </summary>
        /// <param name="fileUploadObject">The file uploading object.</param>
        /// <returns>returns file head of the saved file.</returns>
        public FileHeadObject Save(FileUploadObject fileUploadObject)
        {
            Kit.NotNull(fileUploadObject, "fileUploadObject");
            if (!fileUploadObject.Stream.CanRead)
                throw new ArgumentException(Resources.UnreadableFileStream, "fileUploadObject");

            try
            {
                using (FileManagementDataContext ctx = DataContextFactory.Create<FileManagementDataContext>())
                {
                    File file;
                    if (fileUploadObject.Id != Guid.Empty)
                    {
                        file = ctx.Files.FirstOrDefault(q => q.FileId == fileUploadObject.Id && q.ApplicationId == this.applicationContext.ApplicationId);
                        if (file == null)
                            throw new ArgumentException(Resources.InvalidFileId, "fileUploadObject");

                        // delete related thumbnails
                        this.DeleteThumbnails(fileUploadObject.Id);

                        // delete the file from cache
                        base.RemoveCache(fileUploadObject.Id);

                        file.UpdatedOn = DateTime.UtcNow;
                        file.Version++;
                    }
                    else
                    {
                        file = new File
                        {
                            FileId = Guid.NewGuid(),
                            ApplicationId = this.applicationContext.ApplicationId,
                            CreatedOn = DateTime.UtcNow,
                            Version = 1
                        };

                        ctx.Files.InsertOnSubmit(file);
                    }

                    file.Description = fileUploadObject.Description;
                    file.Category = fileUploadObject.Category;
                    file.Name = fileUploadObject.FileName;
                    file.ExtensionName = Path.GetExtension(fileUploadObject.FileName).Substring(1);
                    file.BytesCount = this.fileStorageApi.Store(this.applicationContext.ApplicationId, fileUploadObject.Category, file.FileId, file.ExtensionName, fileUploadObject.Stream);

                    ctx.SubmitChanges();
                    fileUploadObject.Id = file.FileId;

                    return new FileHeadObject
                    {
                        Id = file.FileId,
                        BytesCount = file.BytesCount,
                        Category = file.Category,
                        Description = file.Description,
                        FileExtensionName = file.ExtensionName,
                        FileName = file.Name,
                        CreatedOn = LocalizationUtility.ConvertUtcTimeToClientTime(file.CreatedOn),
                        UpdatedOn = LocalizationUtility.ConvertUtcTimeToClientTime(file.UpdatedOn),
                        Version = file.Version
                    };
                }
            }
            catch (ArgumentException)
            {
                throw;
            }
            catch (Exception exp)
            {
                Logger.Instance(this).Error(exp);
                throw;
            }
        }
        /// <summary>
        /// 上传多个文件
        /// </summary>
        /// <param name="saveForm"></param>
        /// <returns></returns>
        public string SaveMultipleUploadFiles(FormCollection saveForm)
        {
            DataOperation dataOp = new DataOperation();

            string tableName    = PageReq.GetForm("tableName");
            string keyName      = PageReq.GetForm("keyName");
            string keyValue     = saveForm["keyValue"].ToString();
            string localPath    = PageReq.GetForm("uploadFileList");
            string fileSaveType = saveForm["fileSaveType"] != null ? saveForm["fileSaveType"] : "multiply";
            int    fileTypeId   = PageReq.GetFormInt("fileTypeId");
            int    fileObjId    = PageReq.GetFormInt("fileObjId");
            int    uploadType   = PageReq.GetFormInt("uploadType");
            string subMapParam  = PageReq.GetForm("subMapParam");
            string guid2d       = PageReq.GetForm("guid2d");
            string oldGuid2d    = PageReq.GetForm("oldguid2d");
            bool   isPreDefine  = saveForm["isPreDefine"] != null?bool.Parse(saveForm["isPreDefine"]) : false;

            Dictionary <string, string> propDic  = new Dictionary <string, string>();
            FileOperationHelper         opHelper = new FileOperationHelper();
            List <InvokeResult <FileUploadSaveResult> > result = new List <InvokeResult <FileUploadSaveResult> >();

            localPath = localPath.Replace("\\\\", "\\");

            #region 如果保存类型为单个single 则删除旧的所有关联文件
            if (!string.IsNullOrEmpty(fileSaveType))
            {
                if (fileSaveType == "single")
                {
                    opHelper.DeleteFile(tableName, keyName, keyValue);
                }
            }
            #endregion

            #region 通过关联读取对象属性
            if (!string.IsNullOrEmpty(localPath.Trim()))
            {
                string[] fileStr = Regex.Split(localPath, @"\|H\|", RegexOptions.IgnoreCase);
                Dictionary <string, string> filePath = new Dictionary <string, string>();
                foreach (string file in fileStr)
                {
                    string[] filePaths = Regex.Split(file, @"\|Y\|", RegexOptions.IgnoreCase);

                    if (filePaths.Length > 0)
                    {
                        string[] subfile = Regex.Split(filePaths[0], @"\|Z\|", RegexOptions.IgnoreCase);
                        if (subfile.Length > 0)
                        {
                            if (!filePath.Keys.Contains(subfile[0]))
                            {
                                if (filePaths.Length >= 2)
                                {
                                    filePath.Add(subfile[0], filePaths[1]);
                                }
                                else
                                {
                                    filePath.Add(subfile[0], "");
                                }
                            }
                        }
                    }
                }

                if (fileObjId != 0)
                {
                    List <BsonDocument> docs = new List <BsonDocument>();
                    docs = dataOp.FindAllByKeyVal("FileObjPropertyRelation", "fileObjId", fileObjId.ToString()).ToList();

                    List <string> strList = new List <string>();
                    strList = docs.Select(t => t.Text("filePropId")).Distinct().ToList();
                    var doccList = dataOp.FindAllByKeyValList("FileProperty", "filePropId", strList);
                    foreach (var item in doccList)
                    {
                        var formValue = saveForm[item.Text("dataKey")];
                        if (formValue != null)
                        {
                            propDic.Add(item.Text("dataKey"), formValue.ToString());
                        }
                    }
                }

                List <FileUploadObject> singleList = new List <FileUploadObject>(); //纯文档上传
                List <FileUploadObject> objList    = new List <FileUploadObject>(); //当前传入类型文件上传
                foreach (var str in filePath)
                {
                    FileUploadObject obj = new FileUploadObject();
                    obj.fileTypeId   = fileTypeId;
                    obj.fileObjId    = fileObjId;
                    obj.localPath    = str.Key;
                    obj.tableName    = tableName;
                    obj.keyName      = keyName;
                    obj.keyValue     = keyValue;
                    obj.uploadType   = uploadType;
                    obj.isPreDefine  = isPreDefine;
                    obj.isCover      = false;
                    obj.propvalueDic = propDic;
                    obj.rootDir      = str.Value;
                    obj.subMapParam  = subMapParam;
                    obj.guid2d       = guid2d;
                    if (uploadType != 0 && (obj.rootDir == "null" || obj.rootDir.Trim() == ""))
                    {
                        singleList.Add(obj);
                    }
                    else
                    {
                        objList.Add(obj);
                    }
                }

                result = opHelper.UploadMultipleFiles(objList, (UploadType)uploadType);//(UploadType)uploadType
                if (singleList.Count > 0)
                {
                    result = opHelper.UploadMultipleFiles(singleList, (UploadType)0);
                }
            }
            else
            {
                PageJson jsonone = new PageJson();
                jsonone.Success = false;
                return(jsonone.ToString() + "|");
            }
            #endregion

            PageJson json = new PageJson();
            var      ret  = opHelper.ResultConver(result);

            #region 如果有关联的文件Id列表,则保存关联记录
            string     fileVerIds    = PageReq.GetForm("fileVerIds");
            List <int> fileVerIdList = fileVerIds.SplitToIntList(",");

            if (ret.Status == Status.Successful && fileVerIdList.Count > 0)
            {
                List <StorageData> saveList = new List <StorageData>();
                foreach (var tempVerId in fileVerIdList)
                {
                    StorageData tempData = new StorageData();

                    tempData.Name     = "FileAlterRelation";
                    tempData.Type     = StorageType.Insert;
                    tempData.Document = new BsonDocument().Add("alterFileId", result.FirstOrDefault().Value.fileId.ToString())
                                        .Add("fileVerId", tempVerId);

                    saveList.Add(tempData);
                }

                dataOp.BatchSaveStorageData(saveList);
            }
            #endregion

            json.Success = ret.Status == Status.Successful ? true : false;
            var strResult = json.ToString() + "|" + ret.Value + "|" + keyValue;
            return(strResult);
        }
Example #7
0
        /// <summary>
        /// 上传多个文件
        /// </summary>
        /// <param name="saveForm"></param>
        /// <returns></returns>
        public string SaveMultipleUploadFiles(FormCollection saveForm)
        {
            string tableName = PageReq.GetForm("tableName");

            tableName = !string.IsNullOrEmpty(PageReq.GetForm("tableName")) ? PageReq.GetForm("tableName") : PageReq.GetForm("tbName");
            var formKeys = saveForm.AllKeys;

            if (tableName == "" && formKeys.Contains("tableName"))
            {
                tableName = saveForm["tableName"];
            }
            if (tableName == "" && formKeys.Contains("tbName"))
            {
                tableName = saveForm["tbName"];
            }
            string keyName  = formKeys.Contains("keyName") ? saveForm["keyName"] : PageReq.GetForm("keyName");
            string keyValue = formKeys.Contains("keyValue") ? saveForm["keyValue"] : PageReq.GetForm("keyValue");

            if (string.IsNullOrEmpty(keyName))
            {
                keyName = saveForm["keyName"];
            }
            if (string.IsNullOrEmpty(keyValue) || keyValue == "0")
            {
                keyValue = saveForm["keyValue"];
            }
            string localPath    = saveForm.AllKeys.Contains("uploadFileList") ? saveForm["uploadFileList"] : PageReq.GetForm("uploadFileList");
            string fileSaveType = saveForm["fileSaveType"] != null ? saveForm["fileSaveType"] : "multiply";
            int    fileTypeId   = PageReq.GetFormInt("fileTypeId");

            if (formKeys.Contains("fileTypeId"))
            {
                int.TryParse(saveForm["fileTypeId"], out fileTypeId);
            }
            int fileObjId = PageReq.GetFormInt("fileObjId");

            if (formKeys.Contains("fileObjId"))
            {
                int.TryParse(saveForm["fileObjId"], out fileObjId);
            }
            int uploadType = PageReq.GetFormInt("uploadType");

            if (formKeys.Contains("uploadType"))
            {
                int.TryParse(saveForm["uploadType"], out uploadType);
            }
            int fileRel_profId = PageReq.GetFormInt("fileRel_profId");

            if (formKeys.Contains("fileRel_profId"))
            {
                int.TryParse(saveForm["fileRel_profId"], out fileRel_profId);
            }
            int fileRel_stageId = PageReq.GetFormInt("fileRel_stageId");

            if (formKeys.Contains("fileRel_stageId"))
            {
                int.TryParse(saveForm["fileRel_stageId"], out fileRel_stageId);
            }
            int fileRel_fileCatId = PageReq.GetFormInt("fileRel_fileCatId");

            if (formKeys.Contains("fileRel_fileCatId"))
            {
                int.TryParse(saveForm["fileRel_fileCatId"], out fileRel_fileCatId);
            }
            int structId = PageReq.GetFormInt("structId");

            if (formKeys.Contains("structId"))
            {
                int.TryParse(saveForm["structId"], out structId);
            }

            bool isPreDefine = saveForm["isPreDefine"] != null?bool.Parse(saveForm["isPreDefine"]) : false;

            Dictionary <string, string> propDic  = new Dictionary <string, string>();
            FileOperationHelper         opHelper = new FileOperationHelper();
            List <InvokeResult <FileUploadSaveResult> > result = new List <InvokeResult <FileUploadSaveResult> >();

            //替换会到之网络路径错误,如:\\192.168.1.150\D\A\1.jpg
            //localPath = localPath.Replace("\\\\", "\\");

            #region 如果保存类型为单个single 则删除旧的所有关联文件
            if (!string.IsNullOrEmpty(fileSaveType))
            {
                if (fileSaveType == "single")
                {
                    //opHelper.DeleteFile(tableName, keyName, keyValue);
                    opHelper.DeleteFile(tableName, keyName, keyValue, fileObjId.ToString());
                }
            }
            #endregion

            #region 通过关联读取对象属性
            if (!string.IsNullOrEmpty(localPath.Trim()))
            {
                string[] fileStr = Regex.Split(localPath, @"\|H\|", RegexOptions.IgnoreCase);
                Dictionary <string, string> filePath     = new Dictionary <string, string>();
                Dictionary <string, string> filePathInfo = new Dictionary <string, string>();
                string s = fileSaveType.Length.ToString();
                foreach (string file in fileStr)
                {
                    if (string.IsNullOrEmpty(file))
                    {
                        continue;                            // 防止空数据插入的情况
                    }
                    string[] filePaths = Regex.Split(file, @"\|Y\|", RegexOptions.IgnoreCase);

                    if (filePaths.Length > 0)
                    {
                        string[] subfile = Regex.Split(filePaths[0], @"\|Z\|", RegexOptions.IgnoreCase);
                        if (subfile.Length > 0)
                        {
                            if (!filePath.Keys.Contains(subfile[0]))
                            {
                                if (filePaths.Length == 3)
                                {
                                    filePath.Add(subfile[0], filePaths[1]);
                                    filePathInfo.Add(subfile[0], filePaths[2]);
                                }
                                else if (filePaths.Length == 2 || filePaths.Length > 3)
                                {
                                    filePath.Add(subfile[0], filePaths[1]);
                                }
                                else
                                {
                                    filePath.Add(subfile[0], "");
                                }
                            }
                        }
                    }
                }

                if (fileObjId != 0)
                {
                    List <BsonDocument> docs = new List <BsonDocument>();
                    docs = dataOp.FindAllByKeyVal("FileObjPropertyRelation", "fileObjId", fileObjId.ToString()).ToList();

                    List <string> strList = new List <string>();
                    strList = docs.Select(t => t.Text("filePropId")).Distinct().ToList();
                    var doccList = dataOp.FindAllByKeyValList("FileProperty", "filePropId", strList);
                    foreach (var item in doccList)
                    {
                        var formValue = saveForm[item.Text("dataKey")];
                        if (formValue != null)
                        {
                            propDic.Add(item.Text("dataKey"), formValue.ToString());
                        }
                    }
                }
                #region 文档直接关联属性

                foreach (var tempKey in saveForm.AllKeys)
                {
                    if (!string.IsNullOrEmpty(tempKey) && tempKey.Contains("Property_"))
                    {
                        var formValue = saveForm[tempKey];
                        propDic.Add(tempKey, formValue.ToString());
                    }
                }

                #endregion

                List <FileUploadObject> singleList = new List <FileUploadObject>(); //纯文档上传
                List <FileUploadObject> objList    = new List <FileUploadObject>(); //当前传入类型文件上传
                foreach (var str in filePath)
                {
                    FileUploadObject            obj      = new FileUploadObject();
                    List <string>               infoList = new List <string>();
                    Dictionary <string, string> infoDc   = new Dictionary <string, string>();
                    if (filePathInfo.ContainsKey(str.Key))
                    {
                        infoList = Regex.Split(filePathInfo[str.Key], @"\|N\|", RegexOptions.IgnoreCase).ToList();
                        foreach (var tempInfo in infoList)
                        {
                            string[] tempSingleInfo = Regex.Split(tempInfo, @"\|-\|", RegexOptions.IgnoreCase);
                            if (tempSingleInfo.Length == 2)
                            {
                                infoDc.Add(tempSingleInfo[0], tempSingleInfo[1]);
                            }
                        }
                    }
                    if (infoDc.ContainsKey("fileTypeId"))
                    {
                        obj.fileTypeId = Convert.ToInt32(infoDc["fileTypeId"]);
                    }
                    else
                    {
                        obj.fileTypeId = fileTypeId;
                    }
                    if (infoDc.ContainsKey("fileObjId"))
                    {
                        obj.fileObjId = Convert.ToInt32(infoDc["fileObjId"]);
                    }
                    else
                    {
                        obj.fileObjId = fileObjId;
                    }
                    if (filePathInfo.ContainsKey(str.Key))
                    {
                        obj.localPath = Regex.Split(str.Key, @"\|N\|", RegexOptions.IgnoreCase)[0];
                    }
                    else
                    {
                        obj.localPath = str.Key;
                    }
                    if (infoDc.ContainsKey("tableName"))
                    {
                        obj.tableName = infoDc["tableName"];
                    }
                    else
                    {
                        obj.tableName = tableName;
                    }
                    if (infoDc.ContainsKey("keyName"))
                    {
                        obj.keyName = infoDc["keyName"];
                    }
                    else
                    {
                        obj.keyName = keyName;
                    }
                    if (infoDc.ContainsKey("keyValue"))
                    {
                        if (infoDc["keyValue"] != "0")
                        {
                            obj.keyValue = infoDc["keyValue"];
                        }
                        else
                        {
                            obj.keyValue = keyValue;
                        }
                    }
                    else
                    {
                        obj.keyValue = keyValue;
                    }
                    if (infoDc.ContainsKey("uploadType"))
                    {
                        if (infoDc["uploadType"] != null && infoDc["uploadType"] != "undefined")
                        {
                            obj.uploadType = Convert.ToInt32(infoDc["uploadType"]);
                        }
                        else
                        {
                            obj.uploadType = uploadType;
                        }
                    }
                    else
                    {
                        obj.uploadType = uploadType;
                    }
                    obj.isPreDefine = isPreDefine;
                    if (infoDc.ContainsKey("isCover"))
                    {
                        if (infoDc["isCover"] == "Yes")
                        {
                            obj.isCover = true;
                        }
                        else
                        {
                            obj.isCover = false;
                        }
                    }
                    else
                    {
                        obj.propvalueDic = propDic;
                    }
                    if (infoDc.ContainsKey("structId"))
                    {
                        obj.structId = Convert.ToInt32(infoDc["structId"]);
                    }
                    else
                    {
                        obj.structId = structId;
                    }
                    obj.rootDir           = str.Value;
                    obj.fileRel_profId    = fileRel_profId.ToString();
                    obj.fileRel_stageId   = fileRel_stageId.ToString();
                    obj.fileRel_fileCatId = fileRel_fileCatId.ToString();

                    if (uploadType != 0 && (obj.rootDir == "null" || obj.rootDir.Trim() == ""))
                    {
                        singleList.Add(obj);
                    }
                    else
                    {
                        objList.Add(obj);
                    }
                }

                result = opHelper.UploadMultipleFiles(objList, (UploadType)uploadType);//(UploadType)uploadType
                if (singleList.Count > 0)
                {
                    //result = opHelper.UploadMultipleFiles(singleList, (UploadType)0);
                    result.AddRange(opHelper.UploadMultipleFiles(singleList, (UploadType)0));
                }
            }
            else
            {
                PageJson jsonone = new PageJson();
                jsonone.Success = false;
                return(jsonone.ToString() + "|");
            }
            #endregion

            PageJson json = new PageJson();
            var      ret  = opHelper.ResultConver(result);
            json.Success = ret.Status == Status.Successful ? true : false;
            var strResult = json.ToString() + "|" + ret.Value;
            return(strResult);
        }
        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"/> interface.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpContext"/> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param>
        public void ProcessRequest(HttpContext context)
        {
            HttpPostedFile httpPostedFile = context.Request.Files["rapidwebdev.filemanagement"];
            if (httpPostedFile == null)
            {
                context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                context.Response.StatusDescription = Resources.UploadingFileNotFound;
                return;
            }

            string category = context.Request["category"];
            if (string.IsNullOrEmpty(category))
            {
                context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                context.Response.StatusDescription = Resources.FileCategoryQueryStringParameterNotFound;
                return;
            }

            string permissionValue = string.Format(CultureInfo.InvariantCulture, "FileManagement.{0}.Upload", category);
            if (!permissionBridge.HasPermission(permissionValue))
            {
                context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                context.Response.StatusDescription = Resources.NoPermissionToUploadFiles;
                return;
            }

            FileUploadObject fileUploadObject = new FileUploadObject
            {
                FileName = Path.GetFileName(httpPostedFile.FileName),
                Category = category,
                Stream = httpPostedFile.InputStream
            };

            FileHeadObject fileHeadObject = fileManagementApi.Save(fileUploadObject);
            FileWebObject fileObject = new FileWebObject(fileHeadObject.Id, fileHeadObject.FileName, fileHeadObject.BytesCount);
            string fileJson = serializer.Serialize(fileObject);

            context.Response.Clear();
            context.Response.StatusCode = (int)HttpStatusCode.OK;
            context.Response.ContentType = "application/json";
            context.Response.Write(fileJson);
            context.Response.End();
        }