当我使用Amazon S3 multipart上载文件然后正在加载时,该文件未成功上载。 uploadRequest_UploadPartProgressEvent
中的e.PercentDone
在 protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
extension = Path.GetExtension(FileUpload1.FileName);
fileSize = FileUpload1.PostedFile.ContentLength;
Stream st = FileUpload1.PostedFile.InputStream;
string name = Path.GetFileName(FileUpload1.FileName);
string fName = Path.GetFileNameWithoutExtension(name);
string fExt = Path.GetExtension(name);
string strRes = String.Concat(fName, builder.ToString());
string strRes1 = String.Concat(strRes, fExt);
string s3FileName = @strRes1;
stt = st;
fileNameInS3 = s3FileName;
bool a;
TrackMPUAsync().Wait();
}
}
public async Task TrackMPUAsync()
{
try
{
TransferUtility fileTransferUtility = new TransferUtility(s3Client);
// Use TransferUtilityUploadRequest to configure options.
// In this example we subscribe to an event.
TransferUtilityUploadRequest uploadRequest =
new TransferUtilityUploadRequest
{
BucketName = bucketName + @"/" + foldername,
Key = filename,
InputStream = fileInputStrem
};
uploadRequest.UploadProgressEvent +=
new EventHandler<UploadProgressArgs>
(uploadRequest_UploadPartProgressEvent);
await fileTransferUtility.UploadAsync(uploadRequest);
Console.WriteLine("Upload completed");
}
catch (AmazonS3Exception e)
{
Console.WriteLine("Error encountered on server. Message:'{0}' when writing an object", e.Message);
}
catch (Exception e)
{
Console.WriteLine("Unknown encountered on server. Message:'{0}' when writing an object", e.Message);
}
}
public void uploadRequest_UploadPartProgressEvent(object sender,
UploadProgressArgs e)
{
// Process event.
Console.WriteLine("{0}/{1}", e.TransferredBytes, e.TotalBytes);
}
为100后面临加载问题,网页正在加载无穷大时间。
const { createArray, getArray } = require ('./function')
window.onload = () => {
createArray()
sessionStorage.setItem("Array", getArray)
console.log(sessionStorage.getItem("Array") //[object Object],[object Object],[object Object]
console.log(getArray) // [{"1": 10}, {"2": 11}, {"3": 12}]
}
其他人遇到过这个问题吗?
答案 0 :(得分:0)
对于获得可行的解决方案,我有一些建议,但是老实说,我没有运行您的代码(这是基于快速检查代码的结果)。首先,必须将BucketName
属性设置为存储桶[1]的确切名称,因此您不应该在其中添加文件夹名称。而是应在Key
上将文件夹名称添加为前缀:
BucketName = bucketName,
Key = foldername + @"/" + filename,
接下来,使用Console.WriteLine
可能很难看到捕获的错误。看来这是WinForms应用程序的一部分,因此也许使用Debug.WriteLine()
[2]在Visual Studio(或代码等)中显示错误是一个好主意。
最后,也许重要的是,在事件处理程序中使用TrackMPUAsync().Wait()
是同步的,并且会阻塞直到上传完成[3],相反,您可能希望异步执行上传:
Task.Run(() => TrackMPUAsync());
希望这会有所帮助。
[1] https://docs.aws.amazon.com/AmazonS3/latest/dev/HLuploadFileDotNet.html
[2] https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.debug.writeline