我的for应该只运行一次就运行两次

时间:2020-10-29 19:39:26

标签: javascript

我有一个请求上传图片的地方。它应该只运行一次,但是运行两次,因此上载相同的图像两次。 我找不到错误,在我看来它具有正确的参数

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)
              })
          }
        }
      });
  }

0 个答案:

没有答案
相关问题