如何编码<输入文件>在AngularJs中进行base64 [英] How to Encode an <input file> to base64 in AngularJs?

查看:244
本文介绍了如何编码<输入文件>在AngularJs中进行base64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过drupal服务/文件将图像保存到Drupal中。对于我的理解,我需要将文件解码为base64,并将其作为服务/文件的有效载荷发送。为了做到这一点我怎么可以编码?我想在javascript中这样做。

I need to save an image into Drupal, through the drupal service/file. For what i understand i need to decode the file into a base64 and send this as a payload for the service/file. How can i get to encode the in order to do this???? I want to do this in javascript.

推荐答案

我是 angular-base64-upload ,如@GrimurD所述​​。该指令适用于此场景。它将图像(或任何其他文件类型)解析为base64编码,并将文件信息附加到范围中的模型。

I am the author of angular-base64-upload as mentioned by @GrimurD. This directive works perfectly for this scenario. It parses image(or any other file types) into base64-encoding and attach the file info to a model in your scope.

样本用法:

<input type='file' ng-model='yourModel' base-sixty-four-input>

一旦您选择了一个文件, yourModel 将具有以下价值:

Once you selected a file, yourModel will have a value of something like:

{
  "filetype": "text/plain",
  "filename": "textfile.txt",
  "base64": "/asdjfo4sa]f57as]fd42sdf354asdf2as35fd4"
}

它还具有使用PHP或ruby解码服务器中base64文件的示例代码。

It also has sample code for decoding the base64 file in your server, using PHP or ruby.

这篇关于如何编码&lt;输入文件&gt;在AngularJs中进行base64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆