gpt4 book ai didi

javascript - 上传到 amazon s3 非常慢

转载 作者:行者123 更新时间:2023-11-30 14:49:13 31 4
gpt4 key购买 nike

我正在使用带有 boto3 库的 python-flask 应用程序在 Amazon S3 上上传图像,但对于 1MB 大小 - 3MB 大小,上传需要 16-18 秒。我缺少什么请提出建议。

function readFile(evt) {
var file = evt.target.files[0];
var reader = new FileReader();
output_format = "jpg";
reader.onload = function(event) {
var i = document.getElementById("source_image");
i.src = event.target.result;
i.onload = function(){
image_width=$(i).width(),
image_height=$(i).height();

if(image_width > image_height){
i.style.width="320px";
}else{
i.style.height="300px";
}
i.style.display = "block";
console.log("Image loaded");
}
};

console.log("Filename:" + file.name);
console.log("Filesize:" + (parseInt(file.size) / 1024) + " Kb");
console.log("Type:" + file.type);
reader.readAsDataURL(file);

return false;
}

document.getElementById('fileinput').addEventListener('change', readFile, false);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="upload_form" action="/updateuser" method="POST" enctype="multipart/form-data">
<label for="file">Choose file</label>
<input type="file" id="fileinput" />
<img id="source_image">
<input type="button" id="upload" value="uploadimage">
</form>

下面是我的python代码

我从配置文件中导入了 S3_KEY、S3_SECRET、S3_BUCKET,创建了 boto3 客户端实例,并使用 s3.upload_fileobj() 将文件上传到 Amazon S3。

    import boto3
from config import S3_KEY, S3_SECRET, S3_BUCKET
# Ajax function to support upload image call from UI
@app.route('/user/uploadimage',methods=['GET','POST'])
def uploadimage():
print "In uploadimage()"
starttime = int(round(time.time() * 1000))
print "Start Monitoring uploadimage()",starttime
try:
s3 = boto3.client(
"s3",
aws_access_key_id=S3_KEY,
aws_secret_access_key=S3_SECRET
)
except Exception as e:
print str(e)
try:
file = request.files['file']
s3.upload_fileobj(
file,
S3_BUCKET,
file.filename,
ExtraArgs={
"ACL": "public-read",
"ContentType": file.content_type
}
)
print "File uploaded successfully"
print "Stop Monitoring uploadimage()",(int(round(time.time() * 1000))-starttime)
except Exception as e:
print("Error while Saving Image on Amazon S3 : ", e)

最佳答案

0.5Mbps / 8 = 0,0625 MBps 

1MB / 0,0625 ~ 16 sec

考虑到您的互联网连接,我认为速度没有问题......实际上应该需要更多时间

关于javascript - 上传到 amazon s3 非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48439646/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com