我需要实现上传文件并显示进度条,但我很难理解xhr上传过程以及幕后发生的事情。
在用户界面中,我正在向' / Home / UploadHomeReport'发出ajax请求。并听取进展事件。
[HttpPost]
public async Task<JsonResult> UploadHomeReport(CancellationToken cancellationToken)
{
try
{
foreach (string file in Request.Files)
{
var fileContent = Request.Files[file];
if (fileContent != null && fileContent.ContentLength > 0)
{
// BREAK POINT
var stream = fileContent.InputStream;
var data = 0;
while (data != -1)
data = stream.ReadByte();
}
}
}
catch (Exception)
{
Response.StatusCode = (int)HttpStatusCode.BadRequest;
return Json("Upload failed");
}
return Json("File uploaded successfully");
}
我有一个处理文件的异步控制器方法(现在我只是从流中读出来)
Docker containers 'fails' to 'inherit' the instance profile of the host ec2 even though IAM is assigned.
But it will work smoothly if I re-deploy the docker stack services.
Error log:
Request: POST /exports
** (exit) exited in: GenServer.call(ExAws.Config.Aut`enter code here`hCache, {:refresh_config, %{access_key_id: [{:system, "AWS_ACCESS_KEY_ID"}, :instance_role] http_client: ExAws.Request.Hackney, json_codec: Poison, region: "ap-southeast-1", retries: [max_attempts: 10, base_backoff_in_ms: 10, max_backoff_in_ms: 10000], scheme: "https://", secret_access_key: [{:system, "AWS_SECRET_ACCESS_KEY"}, :instance_role]}}, 30000)
我的问题是,在我实际开始从流中读取之前,当我点击控制器中的断点(由// BREAK POINT表示)时,UI显示100%的进度。
我知道有一些解决方法可以解决这个问题,比如在这种情况下单独调用ajax来检查服务器端处理的状态,但是进度事件监听器的目的是什么? / p>
此外,一旦我点击了断点,是我的应用程序已经加载到内存中的文件(我认为它是因为进度为100%)或从流中读取文件获取文件从浏览器中把它放在内存中?
感谢您的回复!