简体   繁体   English

不允许加载本地资源(图片缩略图)

[英]Not allowed to load local resource (image thumbnail)

I'm making an app that allows one to change the image associated with an mp3 file. 我正在制作一个允许更改与mp3文件关联的图像的应用程序。 Once the image is chosen, a small thumbnail of that image appears on the screen. 选择图像后,屏幕上会出现该图像的小缩略图。 When choosing an image from outside of the project folder, I run into the security error. 从项目文件夹外部选择图像时,遇到了安全错误。 This is new territory for me. 这对我来说是新领域。 What is the protocol for working around this? 解决此问题的协议是什么?

I'm also using Vue.js with a simple live server. 我还将Vue.js与简单的实时服务器配合使用。 The only way to make this not happen is to have the image in my project folder, but obviously, people using this app won't have that. 避免这种情况的唯一方法是将图像保存在我的项目文件夹中,但是显然,使用此应用程序的人不会拥有该图像。

<div v-bind:style="styleObject" class="square"></div>

var app = new Vue({
    el: '#app',
    data: {
      styleObject: {
        'background-color': 'white',
        'background-image': 'none'

      }
    },
    methods: {
      updateBG: function(){
        var fullPath = document.getElementById("mp3Artwork").value
        this.styleObject['background-image'] = 'url(' + fullPath + ')'
        console.log(this.styleObject['background-image'])
      }
    },
  })

The console output is: url(C:\\fakepath\\image.jpg) But, the error gives: Not allowed to load local resource: file:///C:/%C3%BAkepath%0image.jpg 控制台输出为:url(C:\\ fakepath \\ image.jpg)但是,错误给出:不允许加载本地资源:file:/// C:/%C3%BAkepath%0image.jpg

You cannot access local files from your computer with an absolute link from your browser using Javascript as it would be a potential security breach. 您不能使用Javascript从浏览器中使用绝对链接从计算机访问本地文件,因为这可能会导致安全漏洞。

You need a relative link from your server. 您需要来自服务器的相对链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM