javascript - my for is running twice when it was supposed to run only once
问题描述
I have a for where there is a request to upload an image. It should run only ONE time, but it is running twice and thus uploading the same image twice. I can't find the error, in my view it has the correct parameters
function uploadImage(itemsUpload) {
requestImage
.get(`images/url`)
.json()
.then(response => {
let number= 1;
for (let i = 0; i < number; i++) {
if (itemsUpload.length > 0) {
const URL = response.url
const newURL = URL.replace('https://store-tst-marketplace.s3.amazonaws.com/', '')
const img = itemsUpload[i]["file"]
let blob = new Blob([img], { type: 'image/png' })
request
.put(`images/upload/${newURL}`, { body: blob, headers: { "content-type": blob.type } })
.then(response => {
console.log(response)
})
}
}
});
}
解决方案
推荐阅读
- c# - 显示用户服务器权限
- c++ - const 映射及其大小
- sql - 将 'DD-MM-YY' 转换为 'Month Year' oracle
- c# - ZStandard 压缩在 MongoDB v4.2.7 中不起作用
- azure - 重新播放/重复/重新触发现有文件的 Azure BlobStorage 函数触发器
- sql - 使用 SQLdeveloper 在 oracle 中插入多个 BLOB 文件
- android - Xampp 无法在 Android 浏览器中加载
- variables - Halcon - 初始化标志性变量的元组
- python - 从 2 个下拉菜单中抓取表格数据
- javascript - 如何在输入时添加 libphonenumber