Angularjs 如何获取本地图像url以存储在firebase中

Angularjs 如何获取本地图像url以存储在firebase中,angularjs,firebase,firebase-realtime-database,Angularjs,Firebase,Firebase Realtime Database,我必须在firebase数据库中存储用户配置文件照片。我想存储一个具有以下路径的本地图像:“www/img/avatar.jpeg”。我尝试使用此代码获取图像url $scope.user.image="data:img/avatar.jpeg;base64" 但是,当运行我的代码时,我收到以下消息错误:ERR\u UNKNOWN\u URL\u SCHEME用户必须选择照片,因此您的HTML中需要一个文件选择器: <input type="file" id="file" name="f

我必须在firebase数据库中存储用户配置文件照片。我想存储一个具有以下路径的本地图像:“www/img/avatar.jpeg”。我尝试使用此代码获取图像url

$scope.user.image="data:img/avatar.jpeg;base64"

但是,当运行我的代码时,我收到以下消息错误:
ERR\u UNKNOWN\u URL\u SCHEME

用户必须选择照片,因此您的HTML中需要一个文件选择器:

<input type="file" id="file" name="file" />

然后,您可以通过以下方式在JavaScript中处理它:

function handleFileSelect(e) {
  var file = e.target.files[0];
  // Get a reference to the location where we'll store our photos
  var storageRef = storage.ref().child('chat_photos');

  // Get a reference to store file at photos/<FILENAME>.jpg
  var photoRef = storageRef.child(file.name);
  // Upload file to Firebase Storage
  var uploadTask = photoRef.put(file);
  uploadTask.on('state_changed', null, null, function() {
    // When the image has successfully uploaded, we get its download URL
    var downloadUrl = uploadTask.snapshot.downloadURL;
    // Set the download URL to the message box, so that the user can send it to the database
    textInput.value = downloadUrl;
  });
}
file.addEventListener('change', handleFileSelect, false);
功能手柄文件选择(e){
var file=e.target.files[0];
//获取存储照片的位置的引用
var storageRef=storage.ref().child('chat_photos');
//获取存储文件在photos/.jpg的引用
var photoRef=storageRef.child(file.name);
//将文件上载到Firebase存储
var uploadTask=photoRef.put(文件);
uploadTask.on('state_changed',null,null,function()){
//当图像成功上传后,我们将获得其下载URL
var downloadUrl=uploadTask.snapshot.downloadUrl;
//将下载URL设置为消息框,以便用户可以将其发送到数据库
textInput.value=下载URL;
});
}
addEventListener('change',handleFileSelect,false);
此代码来自。完整的代码在中提供

当它将下载URL添加到文本框中时,您需要将其保存在数据库中