/// <summary>
        ///     获取上传的文件,返回list集合
        /// </summary>
        /// <param name="type">0:图片,1:音频,2:视频</param>
        /// <returns></returns>
        public List <FileUpload> FileUpload(int type)
        {
            var flv = new List <string> {
                ".mp4", ".rmvb", ".wmv", ".flv"
            };

            var listfileUpload = new List <FileUpload>();

            var tUrl = System.Configuration.ConfigurationManager.AppSettings["TenantwareServerBaseUrl"];
            //var tUrl = "http://192.168.100.65:8261/";

            HttpFileCollectionBase files = Request.Files;

            for (int i = 0; i < files.Count; i++)
            {
                var    fileUpload = new FileUpload();
                string fileName   = Path.GetFileName(files[i].FileName);
                string fileExten  = Path.GetExtension(fileName); //扩展名

                if (type != 2 || (type == 2 && flv.Contains(fileExten.ToLower())))
                {
                    string oldName = "";
                    if (type == 2)
                    {
                        string uploadUrl = string.Format(Server.UrlDecode(ConfigurationManager.AppSettings["WareServerUploadWareUrl"]), fileName, "2", CurrentTenant.TenantName);
                        var    responstr = ExternalWareHelper.GetResponseString(ExternalWareHelper.Upload_Request(uploadUrl, files[i].InputStream, fileName));
                        var    data      = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(responstr);
                        if (data.RecordCount == 1)
                        {
                            string converturl = data.DataList["convertfileurl"];
                            if (!string.IsNullOrWhiteSpace(converturl))
                            {
                                oldName = tUrl + converturl.Replace("\\", "/") + ".mp4";
                            }
                            //fileUpload.FileName = tUrl + "FS/ConvertFileUrl?Id=" + data.DataList["Id"];
                        }
                    }
                    else
                    {
                        oldName = SaveFile(files[i], "~/UploadFiles/ExamQuestionResource/");
                    }
                    //保存的文件名,防止名称冲突
                    fileUpload.FileType = type;
                    fileUpload.RealName = fileName;
                    fileUpload.FileName = oldName;
                    listfileUpload.Add(fileUpload);
                }
            }
            return(listfileUpload);
        }
Example #2
0
        /// <summary>
        /// 上传文件,通过HttpRequest中的Files
        /// </summary>
        /// <param name="file"></param>
        /// <param name="dir">相对路径</param>
        /// <param name="extendName">扩展名</param>
        /// <param name="externalId">外部租户ID</param>
        /// <returns></returns>
        public string Upload(System.Web.HttpPostedFileBase file, string dir, string extendName, int externalId)
        {
            var    uploadUrl = string.Format(FileStoreHost.FileStoreWareUploadUrl, file.FileName, "-1", externalId);
            var    responstr = ExternalWareHelper.GetResponseString(ExternalWareHelper.Upload_Request(uploadUrl, file.InputStream, file.FileName));
            string fileUrl   = string.Empty;
            var    data      = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(responstr);

            if (data.RecordCount == 1)
            {
                string converturl = data.DataList["convertfileurl"];
                if (!string.IsNullOrWhiteSpace(converturl))
                {
                    fileUrl = FileStoreHost.FileStoreUrl + converturl.Replace("\\", "/");
                }
            }
            return(fileUrl);
        }
Example #3
0
        /// <summary>
        /// 上传文件,通过HttpRequest中的Files
        /// </summary>
        /// <param name="data"></param>
        /// <param name="dir">相对路径</param>
        /// <param name="extendName">扩展名</param>
        /// <param name="externalId">外部租户ID</param>
        /// <returns></returns>
        public string Upload(byte[] data, string dir, string extendName, int externalId)
        {
            var fileName = Guid.NewGuid().ToString("N") + "." + extendName;

            Stream stream = new MemoryStream(data);

            var    uploadUrl    = string.Format(FileStoreHost.FileStoreWareUploadUrl, fileName, "-1", externalId);
            var    responstr    = ExternalWareHelper.GetResponseString(ExternalWareHelper.Upload_Request(uploadUrl, stream, fileName));
            string fileUrl      = string.Empty;
            var    dataResponse = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(responstr);

            if (dataResponse.RecordCount == 1)
            {
                string converturl = dataResponse.DataList["convertfileurl"];
                if (!string.IsNullOrWhiteSpace(converturl))
                {
                    fileUrl = FileStoreHost.FileStoreUrl + converturl.Replace("\\", "/");
                }
            }
            return(fileUrl);
        }