Warm tip: This article is reproduced from serverfault.com, please click

javascript-文件池从 s3 加载初始图像

(javascript - File pond load initial image from s3)

发布于 2021-02-09 07:44:58

我想从 vue-file-pond 中的 s3 加载初始图像,但它将 Xhr 请求发送到 s3并被 cors origin policy 阻止(我不使用服务器端选项,因为我通过表单提交图像。)。这是我的文件池标签

            <file-pond
                style="width: 100px; height: 100px"
                name="image"
                ref="image"
                label-idle="Drop files here or <span class='filepond--label-action'>Browse</span>"
                :allow-multiple="false"
                accepted-file-types="image/*"
                style-panel-layout="compact circle"
                image-preview-height="70"
                image-crop-aspect-ratio="1:1"
                image-resize-target-width="100"
                image-resize-target-height="100"
                @removefile="removefile(category.image, 'image')"
                @addfile="addImage"
                v-bind:files="image"
              />
              
              ---------------------------------
        data(){return{
                  image: this.category.image
                  ? [this.storage_url + this.category.image]
                : "",}
           }
               ,
     methods:{
     addImage() {
               this.form.image = this.$refs.image.getFile().file;
            }, 
     }

storage_url 是我的 s3 基本 URL。它只是加载在 img 标签上,但在文件池中......我能做什么?我做了整整一周的噩梦

Questioner
Elahe Karamzade
Viewed
0
Elahe Karamzade 2021-02-10 01:21:16

对于谁可能会与这个问题混淆:一周后,我终于弄明白了。这是因为浏览器缓存。当 s3 URL 在 img 标签中加载时,浏览器将其缓存,而在 XHR 请求中的另一次,它并没有真正像正常请求那样请求。所以我强迫他们不缓存 :) 参考这个StackOverFlow问题