Firebase存储看起来非常酷且易于使用,但我想知道是否有办法在将图像上传到Firebase存储之前调整图像大小,例如,在服务器中使用ImageMagick运行proccess然后使用Firebase SDK运行上传过程但是我注意到Firebase SDK服务器没有存储功能.
火力地堡存储声称这里的iOS版的文件,它
无论网络质量如何,都会执行上传和下载.上传和下载非常强大,这意味着它们会在停止的地方重新启动
所以人们会期望它在上传时处理连接丢失,但似乎没有.
使用iOS中的以下Swift代码,我可以在有连接时执行上传,但如果设备没有连接或者它与网络断开连接,则会进入故障状态.
let storage = FIRStorage.storage().referenceForURL("VALID_URL_REMOVED")
let imagesRef = storage.child("images/test.jpg")
let data = UIImageJPEGRepresentation(observationImage!, 0.7);
let uploadTask = imagesRef.putData(data!, metadata: nil)
uploadTask.observeStatus(.Progress) { snapshot in
// Upload reported progress
if let progress = snapshot.progress {
let percentComplete = 100.0 * Double(progress.completedUnitCount) / Double(progress.totalUnitCount)
print("percent \(percentComplete)")
}
}
uploadTask.observeStatus(.Success) { snapshot in
// Upload completed successfully
print("success")
}
uploadTask.observeStatus(.Failure) { snapshot in
print("error")
print(snapshot.error?.localizedDescription)
}
Run Code Online (Sandbox Code Playgroud)
此代码的调试输出如下.
/*
percent 0.0
percent 0.0044084949781492
2016-06-30 11:49:16.480 Removed[5020:] <FIRAnalytics/DEBUG> Network status …Run Code Online (Sandbox Code Playgroud) 我正在尝试将firebase中的图像显示为html img标记,但无法检索图像.
Javascript代码:
var storageRef = firebase.storage().ref();
var spaceRef = storageRef.child('images/photo_1.png');
var path = spaceRef.fullPath;
var gsReference = storage.refFromURL('gs://test.appspot.com')
storageRef.child('images/photo_1.png').getDownloadURL().then(function(url) {
var test = url;
}).catch(function(error) {
});
Run Code Online (Sandbox Code Playgroud)
HTML代码:
<img src="test" height="125" width="50"/>
Run Code Online (Sandbox Code Playgroud) 您好我之前询问过有关使用Firebase数据库中的Base64显示图像的问题.建议使用firebase存储.我重新编写了代码,所有内容都加载到firebase存储和数据库中.我遇到的问题是当我保存数据时,没有任何内容填充到我的recyclerview中.一切都是空白的.
你可以提供给我这个工作的任何帮助都会很棒.谢谢.
编辑:在我的活动类中,我调用一个按钮clicklistener来激活相机.拍摄照片后,它将保存到Firebase存储.然后我从存储中下载图像并将其显示在recyclerview中.我理解上传部分,但我很难理解下载和显示部分.谢谢.
viewholder:绑定方法
public void bind (ImageProgress progress){
Glide.with(activity).load("").into(image);
}
}
Run Code Online (Sandbox Code Playgroud)
适配器
@Override
public ProgressViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
return new ProgressViewHolder(activity, activity.getLayoutInflater().inflate(R.layout.weight_progress_list, parent, false));
Run Code Online (Sandbox Code Playgroud)
主要活动课
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.weight_progress);
saveButton = (Button) findViewById(R.id.saveButton);
progressStatusEditText = (EditText) findViewById(R.id.progressStatusEditText);
progressList = (RecyclerView) findViewById(R.id.progressList);
mImageButton = (ImageButton) findViewById(R.id.takePictureButton);
capturedImage=(ImageView)findViewById(R.id.capturedImageView);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
progressList.setHasFixedSize(false);
progressList.setLayoutManager(layoutManager);
//take picture button
mImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openCamera();
}
});
mDatabaseReference = database.getReference("Progress");
saveButton.setOnClickListener(new View.OnClickListener() { …Run Code Online (Sandbox Code Playgroud) 有没有办法将多个文件上传到Firebase存储.它可以在单次尝试中上传单个文件,如下所示.
fileButton.addEventListener('change', function(e){
//Get file
var file = e.target.files[0];
//Create storage reference
var storageRef = firebase.storage().ref(DirectryPath+"/"+file.name);
//Upload file
var task = storageRef.put(file);
//Update progress bar
task.on('state_changed',
function progress(snapshot){
var percentage = snapshot.bytesTransferred / snapshot.totalBytes * 100;
uploader.value = percentage;
},
function error(err){
},
function complete(){
var downloadURL = task.snapshot.downloadURL;
}
);
});
Run Code Online (Sandbox Code Playgroud)
如何将多个文件上传到Firebase存储.
我正在开发用户单击图像的android应用程序,它存储在firebase中,云函数处理此图像并以文本文件的形式将输出存储在firebase中.为了在android中显示输出,应用程序会一直检查输出文件是否存在.如果是,则它在应用程序中显示输出.如果不是,我必须等待文件,直到它可用.
我无法找到任何文档来检查Firebase中是否存在任何文件.任何帮助或指示都会有所帮助.
谢谢.
我正在尝试将图像上传到Firebase存储,并将多个特定元数据保存到Firebase Cloud.我用JavaScript编写代码.
目标是将自定义元数据设置为Firebase Cloud,例如从用户必须填写的文本输入字段.
这就是我将图像存储到Firebase存储的方式:
storageRef.child('images/' + file.name).put(file, metadata).then(function(snapshot) {
console.log('Uploaded', snapshot.totalBytes, 'bytes.');
console.log(snapshot.metadata);
var url = snapshot.downloadURL;
console.log('File available at', url);
// [START_EXCLUDE]
document.getElementById('linkbox').innerHTML = '<a href="' + url + '">Click For File</a>';
// [END_EXCLUDE]
}).catch(function(error) {
// [START onfailure]
console.error('Upload failed:', error);
// [END onfailure]
});
// [END oncomplete]
}Run Code Online (Sandbox Code Playgroud)
我不知道如何在上传功能中集成另一项任务来将元数据写入Firebase Cloud.任何帮助将不胜感激!
@eykjs @Sam Storie:谢谢你的帮助.我改变了我的代码.现在,有一个错误,我无法弄清楚,什么是错的.错误:TypeError:undefined不是对象(评估'selectedFile.name')
我的代码:
var selectedFile;
function handleFileSelect(event) {
//$(".upload-group").show();
selectedFile = event.target.files[0];
};
function confirmUpload() {
var metadata = {
contentType: 'image',
customMetadata: {
'dogType': …Run Code Online (Sandbox Code Playgroud)javascript metadata firebase firebase-storage google-cloud-firestore
详情如下:https://issuetracker.google.com/issues/113672049
交叉发布在这里:https://github.com/GoogleCloudPlatform/google-cloud-python/issues/5879)
从Python中的Google Cloud功能使用Firebase存储API时,我收到连接重置错误.
部署的函数调用一个blob-get ie
from firebase_admin import storage
def fn(request):
bucket = 'my-firebase-bucket'
path = '/thing'
blob = storage.bucket(bucket).get_blob(path)
Run Code Online (Sandbox Code Playgroud)
失败是间歇性的; 该功能的成功率约为90%.
在部署后第一次调用函数时,似乎更有可能失败.
python google-cloud-storage google-cloud-functions firebase-storage
我想使用 flutter 构建应用程序,但是我遇到了问题,我尝试从 firebase 存储中获取图像,但是当我运行应用程序时没有出现图像。
\n这是代码。
\nimport 'package:cloud_firestore/cloud_firestore.dart';\nimport 'package:flutter/material.dart';\n\nimport '../widgets/action_bar.dart';\n\nclass HomeTab extends StatelessWidget {\n\n final CollectionReference _productRef = FirebaseFirestore.instance.collection("products");\n\n @override\n Widget build(BuildContext context) {\n return Container(\n child: Stack(\n children: [\n FutureBuilder<QuerySnapshot>(\n future: _productRef.get(),\n builder: (context , snapshot){\n if(snapshot.hasError){\n return Scaffold(\n body: Center(\n child: Text("Error ${snapshot.error}"),\n ),\n );\n }\n\n\n if(snapshot.connectionState == ConnectionState.done){\n return ListView(\n children: snapshot.data!.docs.map((document) {\n return Container(\n child: Image.network(\n "${(document.data() as Map<String, dynamic>)["image"][0]}",\n ),\n //child: Text("name: ${(document.data() as Map<String, dynamic>)["name"]}"),\n );\n }).toList(),\n );\n }\n\n return Scaffold(\n body: …Run Code Online (Sandbox Code Playgroud) 我正在使用react-native-firebase与我们的Firebase帐户一起使用身份验证,防火墙和存储.尝试将照片上传到存储失败,出现未知错误.这是尝试的代码:
_pickImage = async () => {
await this.getCameraRollPermission()
let result = await ImagePicker.launchImageLibraryAsync({
allowsEditing: true,
aspect: [4, 3],
});
console.log(result);
if (!result.cancelled) {
// this.setState({ photoURL: result.uri });
this._handlePhotoChoice(result)
}
};
_handlePhotoChoice = async pickerResult => {
let userId = this.state.userId
firebase
.storage()
.ref('photos/profile_' + userId + '.jpg')
.putFile(pickerResult.uri)
.then(uploadedFile => {
console.log("Firebase profile photo uploaded successfully")
})
.catch(error => {
console.log("Firebase profile upload failed: " + error)
})
}
Run Code Online (Sandbox Code Playgroud)
在iOS模拟器中测试并使用调试器来检测错误我刚刚收到此错误:
"Error: An unknown error has occurred. …Run Code Online (Sandbox Code Playgroud) ios firebase react-native firebase-storage react-native-firebase
firebase-storage ×10
firebase ×7
javascript ×3
android ×2
ios ×2
flutter ×1
html ×1
imagemagick ×1
metadata ×1
python ×1
react-native ×1
swift ×1