【问题标题】:Is it possible to replace file input data with my own image's data?是否可以用我自己的图像数据替换文件输入数据?
【发布时间】:2017-12-23 11:09:18
【问题描述】:

我想知道如何替换<input type="file"> 的文件,单击一个按钮,该按钮将更新为data:image/...;base64 类型的数据。我想这样做是因为服务器将获取input 内的任何内容,而不是我的图像上的内容。

HTML

<input id="fileimage" type="file">

Javascript

document.getElementById('button').onclick = function(){
   var image = document.getElementById("image").src;
   // from 'image' to 'fileimage' (image is under 'data:image/...;base64' type format)
};

我怎样才能做到这一点?

【问题讨论】:

    标签: javascript jquery html image-processing


    【解决方案1】:

    无法覆盖文件输入base64 数据,您唯一能做的就是擦除其中的任何内容。我所做的是将base64 数据保存在一个隐藏的输入中,并在服务器端再次将其解码为一个文件。

    【讨论】:

      猜你喜欢
      • 2014-03-20
      • 1970-01-01
      • 2012-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多