Tag: file upload

C#:HttpClient,上传多个文件时的文件上传进度为MultipartFormDataContent

我正在使用此代码上传多个文件,并且它运行良好。 它使用modernhttpclient库。 public async Task PostImages (int platform, string url, List imageList) { try { int count = 1; var requestContent = new MultipartFormDataContent (); foreach (var image in imageList) { var imageContent = new ByteArrayContent (image); imageContent.Headers.ContentType = MediaTypeHeaderValue.Parse (“image/jpeg”); requestContent.Add (imageContent, “image” + count, “image.jpg”); count++; } var cookieHandler = new NativeCookieHandler (); […]

c#设置uploadFile内容类型

我正在尝试创建一个api调用我的服务器,这将允许我上传.csv文件。 客户端代码 string url = “http://testserver/testapi”; string filePath = @”C:\test.csv”; using (WebClient wc = new WebClient()) { wc.Headers.Add(“Content-Type”, “text/plain”); byte[] responseArray = wc.UploadFile(url, filePath); } 服务器端代码 string savePath = testSavePath; foreach (string f in Request.Files.AllKeys) { HttpPostedFileBase file = Request.Files[f]; file.SaveAs(savePath); } 我在这行byte[] responseArray = wc.UploadFile(url, filePath);上遇到exceptionbyte[] responseArray = wc.UploadFile(url, filePath); 奇怪的是,当我看到Request我看到了 ContentType=”multipart/form-data; boundary=———————8d006b7c2a5452c” 。 […]

如何使用Razor将文件上传到MVC 3中的App_Data / Uploads后查看文件?

我是mvc的新手,我遇到了问题。 我搜遍了所有的答案,我找不到一个,但我很确定有些东西会让我失望。 问题是我将文件上传到App_Data文件夹后不知道如何访问文件。 我使用在所有论坛上找到的相同代码: 对于我的观点,我使用它 @using (Html.BeginForm(“Index”, “Home”, FormMethod.Post, new { enctype=”multipart/form-data” })) { } 对于我的控制器,我使用它 public class HomeController : Controller { // This action renders the form public ActionResult Index() { return View(); } // This action handles the form POST and the upload [HttpPost] public ActionResult Index(HttpPostedFileBase file) { // Verify that the […]

如果浏览器关闭/上传取消,如何停止文件传输

我在MVC3中与HTML5异步上传文件。 如果我有一个大文件,比如大小为1GB,上传完成50%后取消上传或关闭浏览器,它仍会在目标文件夹中保存500MB文件。 如何在控制器和客户端处理此问题? 这是我的控制器动作: [HttpPost] public ActionResult Upload(object fileToUpload1) { var fileName = Request.Headers[“X-File-Name”]; var fileSize = Request.Headers[“X-File-Size”]; var fileType = Request.Headers[“X-File-Type”]; Request.SaveAs(“D:\\uploadimage\\” + fileName, false); if (fileToUpload1 == null) { return Json(true, JsonRequestBehavior.AllowGet); } else { return Json(false, JsonRequestBehavior.AllowGet); } // return Json(false, JsonRequestBehavior.AllowGet); } 这是Javascript: // Uploading – for Firefox, Google Chrome and […]

将多个文件上载到Azure Blob存储

对Windows Azure来说很新鲜。 我已经按照本教程: 教程 。 它完美地工作但是一个限制是,对于我想到的应用程序,需要能够相对快速地上传多个文件。 是否可以修改教程以支持多文件上传,例如,用户可以使用shift-click选择多个文件。 或者,如果有人知道任何好的教程详细说明上述内容? 任何帮助表示赞赏, 谢谢

.net Core 2.0文件上传大小限制

我在.net core 2.0 MVC Web应用程序中上传大文件时遇到了麻烦。 我见过这样的文章,它展示了如何在.net core 2.0中增加文件大小限制: 增加Kestrel的上传请求长度限制 所以,按照这个例子,我尝试了两种选择。 我目前在我的Program.cs中有这个: public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup() .UseKestrel(options => options.Limits.MaxRequestBodySize = null) .Build(); …而我在控制器上的ajax文件上传方法如下所示: [HttpPost] [RequestSizeLimit(1_074_790_400)] [Route(“api/article/uploadfile/{mediaType}”)] public async Task UploadFile(string mediaType) 我使用Request.Form.Files访问上传​​的文件 视图上的javascript如下所示: $(‘#upload-videos’).change(function () { var files = $(“#upload-videos”).get(0).files; uploadMedia(false, files); }) function uploadMedia(isPhoto, files) { var type; if (isPhoto) { […]

CompleteMultipartUploadResponse中的EntityTooSmall

使用.NET SDK v.1.5.21.0 我正在尝试上传一个大文件(63Mb),我正在关注以下示例: http://docs.aws.amazon.com/AmazonS3/latest/dev/LLuploadFileDotNet.html 但是使用帮助器代替孔代码并使用jQuery文件上传 https://github.com/blueimp/jQuery-File-Upload/blob/master/basic-plus.html 我拥有的是: string bucket = “mybucket”; long totalSize = long.Parse(context.Request.Headers[“X-File-Size”]), maxChunkSize = long.Parse(context.Request.Headers[“X-File-MaxChunkSize”]), uploadedBytes = long.Parse(context.Request.Headers[“X-File-UloadedBytes”]), partNumber = uploadedBytes / maxChunkSize + 1, fileSize = partNumber * inputStream.Length; bool lastPart = inputStream.Length < maxChunkSize; // http://docs.aws.amazon.com/AmazonS3/latest/dev/LLuploadFileDotNet.html if (partNumber == 1) // initialize upload { iView.Utilities.Amazon_S3.S3MultipartUpload.InitializePartToCloud(fileName, bucket); } try { […]

在Console Application中浏览文件夹

我目前必须编写代码以允许我读取文件夹的所有文件并将其写入控制台。 下面,我还有使用浏览器从目录中选择单个文件的代码。 我想知道如何使用浏览按钮选择文件夹。 用于检查所有文件的代码 foreach(var path in Directory.GetFiles(@”C:\Name\Folder\”)) { Console.WriteLine(path); // full path Console.WriteLine(System.IO.Path.GetFileName(path)); // file name } 代码打开对话框 OpenFileDialog fileSelectPopUp = new OpenFileDialog(); fileSelectPopUp.Title = “”; fileSelectPopUp.InitialDirectory = @”c:\”; fileSelectPopUp.Filter = “All EXCEL FILES (*.xlsx*)|*.xlsx*|All files (*.*)|*.*”; fileSelectPopUp.FilterIndex = 2; fileSelectPopUp.RestoreDirectory = true; if (fileSelectPopUp.ShowDialog() == DialogResult.OK) { textBox1.Text = fileSelectPopUp.FileName; }

如何将base64字符串转换为图像二进制文件并保存到服务器

作为一个例子,我已经转换了一个带有重新resize的图像的canvas元素,并将其发布到一个现在编码为的隐藏输入字段中 data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD… 然后将此值发布到我需要将此字符串转换为图像并保存到服务器上的同一页面。 代码背后的文件(upload.aspx) protected void btnUpload_Click(object sender, EventArgs e) { HttpPostedFile filePosted = Request.Files[“newinput”]; string base64String = filePosted.ToString(); // Convert Base64 String to byte[] byte[] imageBytes = Convert.FromBase64String(base64String); MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length); // Convert byte[] to Image ms.Write(imageBytes, 0, imageBytes.Length); System.Drawing.Image image = System.Drawing.Image.FromStream(ms, true); //I DONT KNOW HOW TO WRITE […]

IFormFile没有被dropzone uploadMultiple请求填充

我遇到的问题是IFormFile列表没有填充给定的文件,但是当我调用HttpContext.Request.Form.Files时; 然后我可以访问这些文件。 我更喜欢使用IFormFile,因为它似乎是新的Dotnet核心2.0的做事方式。 我有以下请求有效负载: 使用以下请求标头: 和Razor页面处理程序: public async Task OnPostSend(ConditionResponse conditionResponse) { var files = HttpContext.Request.Form.Files; } 条件响应模型: public class ConditionResponse { public List Plots { get; set; } public string Comments { get; set; } public List Files { get; set; } }