示例#1
0
        public async Task InsertImageClick()
        {
            Message = null;
            if (file != null)
            {
                if (!ImageHelper.IsImageExtension(fileInfo.Type))
                {
                    Message = "File type not allowed, please choose an image";
                    return;
                }
                isLoading = true;
                using (var ms = await file.CreateMemoryStreamAsync(4 * 1024))
                {
                    var content = new MultipartFormDataContent();
                    content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
                    content.Add(new StreamContent(ms, Convert.ToInt32(ms.Length)), "file", fileInfo.Name);
                    var response = await _api.UploadFile <FileStore_Model>("FileStore/Image/CMS.Contents/true", content);

                    if (response != null)
                    {
                        if (response.Status == 200 && !response.Data.name.isNOEOW())
                        {
                            await InsertImage.InvokeAsync(response.Data.url);

                            await _JSRuntime.InvokeVoidAsync("Benriya.closeModal", "#FormInsertImage");
                        }
                        else
                        {
                            Message = response.Message;
                        }
                    }
                }
                isLoading = false;
            }
            else if (!image_url.isNOEOW())
            {
                await InsertImage.InvokeAsync(image_url);

                await _JSRuntime.InvokeVoidAsync("Benriya.closeModal", "#FormInsertImage");
            }
            else
            {
                Message = "Please choose your an image";
            }
        }
        public async Task InsertImageClick()
        {
            Message = null;
            if (file != null)
            {
                var block = new string[] { "download", "script", "exe", "command", "bat", "com", "db", "js", "ja", "xa", "ii", "is", "ha", "bin", "cmd" };
                if (block.Any(fileInfo.Type.Contains))
                {
                    Message = "File type not allowed, please choose a correct file.";
                    return;
                }
                using (var ms = await file.CreateMemoryStreamAsync(4 * 1024))
                {
                    var content = new MultipartFormDataContent();
                    content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
                    content.Add(new StreamContent(ms, Convert.ToInt32(ms.Length)), "file", fileInfo.Name);
                    var response = await _api.UploadFile <T>($"FileStore/Image/{Module}/{IsPublic}?width={Width}&height={Height}", content);

                    if (response != null)
                    {
                        if (response.Status == 200 && response.Data != null)
                        {
                            //T xdata = response.Data;
                            //Type model = xdata.GetType();
                            //PropertyInfo uri_prop = model.GetProperty("url");
                            //Console.WriteLine(uri_prop.GetValue(xdata).ToString());
                            //var file_content = await _api.GetFile(uri_prop.GetValue(xdata).ToString());
                            //PropertyInfo content_prop = model.GetProperty("file_content");
                            //content_prop.SetValue(xdata,file_content,null);
                            //await InsertImage.InvokeAsync(xdata);
                            await InsertImage.InvokeAsync(response.Data);
                        }
                        else
                        {
                            Message = response.Message;
                        }
                    }
                }
            }
            else
            {
                Message = "Please choose your an image";
            }
        }