Tag: file upload

FileUpload控件在第二次单击时工作但不首先尝试保存已发布的文件?

我的问题 我设法回答了自己,但是同样的function还有另外一个问题。 由于某种原因,发布文件的保存事件的第一次回发命中Ol’对象未设置为对象错误的实例,但是第二次尝试上载文件并触发我的保存事件(转换为byte []存储为SQL Server BLOB)它确实应该做的一切。 同样的问题在这里 有一个很好的建议使用AJAX AsyncUpload控件,但我坚信要消除原因而不是解决问题。 我将继续沿着这条路走下去,以便最好地了解asp.net等。 你们中间会有一个wizrd可以帮助我找出为什么我在第一次回发时得到“对象引用没有设置为obj的错误”但是第二次它工作正常。 内容页面具有主页面,其在更新面板中包装内容页面。 不是我决定这样做的。 还有一个更新面板,其中包含针对我的保存事件的回发触发器。 你有什么想法?

如何使用C#HttpClient PostAsync显示上传进度

我正在使用Xamarin PCL为Android和iOS创建文件上传应用程序,我已设法实现文件上传和某种进度条,但它无法正常工作。 我在堆栈溢出时看到了一些显示下载进度的答案,但我想通知我的用户有关上传进度的信息并且没有找到任何解决方案。 这是我的代码: public static async Task PostFileAsync (Stream filestream, string filename, int filesize) { var progress = new System.Net.Http.Handlers.ProgressMessageHandler (); //Progress tracking progress.HttpSendProgress += (object sender, System.Net.Http.Handlers.HttpProgressEventArgs e) => { int progressPercentage = (int)(e.BytesTransferred*100/filesize); //Raise an event that is used to update the UI UploadProgressMade(sender, new System.Net.Http.Handlers.HttpProgressEventArgs(progressPercentage, null, e.BytesTransferred, null)); }; using (var […]

HttpClient:如何一次上传多个文件

我正在尝试使用System.Net.Http.HttpClient上传多个文件。 using (var content = new MultipartFormDataContent()) { content.Add(new StreamContent(imageStream), “image”, “image.jpg”); content.Add(new StreamContent(signatureStream), “signature”, “image.jpg.sig”); var response = await httpClient.PostAsync(_profileImageUploadUri, content); response.EnsureSuccessStatusCode(); } 这只发送mulipart / form-data,但我预计会在post中的某个地方使用multipart / mixed。 更新:好的,我到了。 using (var content = new MultipartFormDataContent()) { var mixed = new MultipartContent(“mixed”) { CreateFileContent(imageStream, “image.jpg”, “image/jpeg”), CreateFileContent(signatureStream, “image.jpg.sig”, “application/octet-stream”) }; content.Add(mixed, “files”); var response = […]

上传的Docx文件已损坏

我们的一个内部网站允许用户上传文档并将文件存储到SQL 2008数据库中。 我们遇到的问题是,当您尝试打开它们时,docx总是说已损坏。 单击确定后,他们然后继续打开罚款。 我做错了什么? (所有其他文件类型保存正常,包括.doc) 上传代码: // save the files string mimeType = Request.Files[i].ContentType; string filePath = Path.GetFileName(Request.Files[i].FileName); string fileName = Path.GetFileName(Request.Files[i].FileName); Stream fileStream = Request.Files[i].InputStream; long fileLength = Request.Files[i].InputStream.Length; if (fileLength > 0) { byte[] fileData = new byte[fileLength]; fileStream.Read(fileData, 0, (int)fileLength); _fileRepo.SaveFileToDatabase(_currentUser.Username, t.EncounterId, fileName, filePath, mimeType, fileData); } 将其插入数据库的代码 tblDocumentImage img = […]

如何使用restsharp上传多个文件?

我想上传文件到这个api https://support.crowdin.com/api/add-file/ 如何使用RestSharp创建名为files的参数并向其添加多个文件? 我到目前为止编写了这段代码,但它不起作用,RestSharp似乎没有按预期上传文件。 var addUrl = new Uri($”https://api.crowdin.com/api/project/{projectIdentifier}/add-file?key={projectKey}&json=”); var restClient = new RestSharp.RestClient(“https://api.crowdin.com”); var request = new RestSharp.RestRequest($”api/project/{projectIdentifier}/add-file”, RestSharp.Method.POST); request.AlwaysMultipartFormData = true; request.AddQueryParameter(“key”, projectKey); request.AddQueryParameter(“json”, “”); var files = new Dictionary { { “testfile”, File.ReadAllBytes(fileName) } }; request.AddParameter(“files”, files, RestSharp.ParameterType.RequestBody); var restResponse = restClient.Execute(request); 这给了我 { “success”:false, “error”:{ “code”:4, “message”:”No files specified in request” […]

如何在上传后重命名文件

我必须在服务器上使用Ftp协议上传文件,并在上传后重命名上传的文件。 我可以上传它,但不知道如何重命名它。 代码如下所示: FtpWebRequest requestFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(“ftp://” + ftpServer + “/” + “httpdocs/webroot/” + destination + “/” + fileName)); requestFTP.Proxy = null; requestFTP.Credentials = new NetworkCredential(ftpUser, ftpPassword); requestFTP.Method = WebRequestMethods.Ftp.UploadFile; FileStream fStream = fileInfo.OpenRead(); int bufferLength = 2048; byte[] buffer = new byte[bufferLength]; Stream uploadStream = requestFTP.GetRequestStream(); int contentLength = fStream.Read(buffer, 0, bufferLength); while […]

WebAPI上传错误。 MIME多部分流的预期结束。 MIME多部分消息未完成

作为MVC4的WebAPI的一部分,我一直在关注本教程以支持文件上传: http : //blogs.msdn.com/b/henrikn/archive/2012/03/01/file-upload-and-asp-net-web -api.aspx 。 当我的控制器收到请求时,它会抱怨“MIME多部分消息未完成”。 有没有人有关于如何调试这个的任何提示? 我已经尝试将流的位置重置为0,因为在它遇到处理程序之前还有其他东西在读取它之前。 我的HTML看起来像这样: Select file(s) to upload : 和我的控制器的Post方法如下: public Task<IEnumerable> Post() { if (Request.Content.IsMimeMultipartContent()) { Stream reqStream = Request.Content.ReadAsStreamAsync().Result; if (reqStream.CanSeek) { reqStream.Position = 0; } string fullPath = HttpContext.Current.Server.MapPath(“~/App_Data”); var streamProvider = new MultipartFormDataStreamProvider(fullPath); var task = Request.Content.ReadAsMultipartAsync(streamProvider).ContinueWith(t => { if (t.IsFaulted || t.IsCanceled) Request.CreateErrorResponse(HttpStatusCode.InternalServerError, t.Exception); […]

使用参数将照片上传到PHP页面

我需要通过.php文件上传文件服务器,我有这个信息: 使用以下参数调用:/uploadFiles.php: $ _ POST [ ‘user_id说明’] $ _FILES [ ‘图像’] 所以,我的问题是“用参数$ _GET [‘user_id’]调用php和$ _FILES [‘image’]”是什么意思,我如何成功调用php。 我已经为了其他需要,通过“POST”方法成功调用了服务器,如下所示: var client = WebClient(); client.UploadStringCompleted += new UploadStringCompletedEventHandler(client_UploadStringCompleted); client.Headers[“Content-Type”] = “application/x-www-form-urlencoded”; client.Encoding = Encoding.UTF8; string toSend = “http://example.com/submit.php?userid=10”; client.UploadStringAsync(new Uri(toSend), “POST”, “”); 当然,我在发布之前做了很多研究,尝试过很多来自主题的解决方案: https : //stackoverflow.com/search?q = wp7 + photo + upload 预先感谢您的帮助。 更新: 我发现我需要的是模拟这个简单的HTML UPLOAD表单: File to […]

通过SkyDrive API将文件上传到skydrive

我尝试将文本文件上传到我的skydrive或者至少在SD中创建新的文本文件并通过我的Windows 8应用程序中的SkyDrive API编辑它的内容。 我怎样才能做到这一点? 我试着这样做: LiveConnectClient client = new LiveConnectClient(session); var fileData = new Dictionary(); fileData.Add(“name”, “new_file.txt”); try { LiveOperationResult fileOperationResult = await client.PutAsync(“me/skydrive”, fileData); this.infoTextBlock.Text = fileOperationResult.ToString(); } catch (LiveConnectException exception) { this.infoTextBlock.Text = exception.Message; } 但我收到错误“提供的请求无效。无法更新根SkyDrive文件夹。” 如果我写了类似“me / skydrive /”的内容,我会收到“提供的URL无效。不支持请求的路径”。 方法LiveConnectClient.PutAsync只允许我更新现有属性(但不是它的内容)。 应该如何正确地完成? 顺便说一句 – LCDC上的内容(http://msdn.microsoft.com/en-us/library/live/hh826531.aspx)是否已更新? 我问,因为dlls中不存在文档中的某些方法(fe LiveConnectClient.Upload。只有BackgroundUploadAsync)。 感谢您提前帮助,Micheal

嵌套在UpdatePanel中时FileUpload不起作用? C#

按钮1位于更新面板之外,当用户在上传框中添加文件时运行的javascript是: function clickTheButton() { document.getElementById(”).click(); } 问题很简单。 FileUpload1.HasFile == false。 我不知道为什么会这样,但当我把它放在更新面板中时它就不再起作用了。 我已经看到了其他一些线索。 但他们都没有回答为什么会这样,他们只是指出你可以下载的东西。 编辑:我真正想要这样做的主要原因是,我可以获得一个..上传文件..标签在客户端上传到服务器时弹出,一旦完成,就显示在数据列表中。 我不能让UpdateProgress工作。