我使用节点js express和firebase创建了一个Web应用程序。我创建了一个将文件上传到firebase的表单,但是当我尝试指南上的内容时,它会出错...
var firebase = require('firebase');
var config = {
apiKey: "----------------------------------",
authDomain: "----------------------------------",
databaseURL: "-",----------------------------------
projectId: "---------",
storageBucket: "----------------",
messagingSenderId: "---------------"
};
firebase.initializeApp(config);
module.exports = firebase;
// Get a reference to the storage service, which is used to create references in your storage bucket
var storage = firebase.storage();
// Create a storage reference from our storage service
var storageRef = storage.ref();
这是我用于在节点js上使用firebase的设置。
var storage = firebase.storage();
^
TypeError: firebase.storage is not a function
这是我从控制台收到的错误。搜索后他们说我需要使用google-cloud npm。所以我的问题是,如果我在我的节点上安装google-cloud,我是否需要在google云平台上创建一个帐户?..
答案 0 :(得分:1)
使用节点js google-cloud软件包而不是firebase来存储文件,视频等。现在firebase存储与Nodejs不兼容,这就是为什么你会收到这个错误^,你可以做类似这样的事情使用google-cloud: -
public class MyBottomsheetBehaviour extends BottomSheetBehavior {
int lastY = 0;
MyBottomsheetBehaviour() {
super();
}
@Keep
public MyBottomsheetBehaviour(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, View view, MotionEvent event) {
int dy = 0;
boolean shouldWeConsumeIt = false;
if (event.getAction() == MotionEvent.ACTION_DOWN) {
lastY = (int) event.getY();
} else if (event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP) {
lastY = 0;
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
dy = (int) event.getY() - lastY;
}
Log.d("Swapnil", "onInterceptTouchEvent() event Y=" + event.getY() + " x=" + event.getX() + getActionType(event.getActionMasked()) + view.getClass().getSimpleName() + "dy=" + dy);
if (view instanceof FrameLayout) {
View child = ((ViewGroup) ((FrameLayout) view).getChildAt(0)).getChildAt(0);
LinearLayoutManager manager = (LinearLayoutManager) ((RecyclerView) child).getLayoutManager();
if (manager.findFirstCompletelyVisibleItemPosition() == 0 && dy > 0) {
shouldWeConsumeIt = true;
int parentHeight = view.getHeight();
ViewCompat.offsetTopAndBottom(view, dy);
} else if (manager.findFirstCompletelyVisibleItemPosition() == 0) {
int height = ((View) view.getParent()).getHeight();
int top = view.getTop();
if ((event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP) && top < (height >> 2)) {
view.setTop(0);
setState(BottomSheetBehavior.STATE_EXPANDED);
} else if ((event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP)) {
setState(BottomSheetBehavior.STATE_COLLAPSED);
}
}
}
if (event.getAction() == MotionEvent.ACTION_MOVE) {
lastY = (int) event.getY();
}
if (!shouldWeConsumeIt)
return super.onInterceptTouchEvent(parent, view, event);
return true;
}
@Override
public boolean onTouchEvent(CoordinatorLayout parent, View child, MotionEvent event) {
return super.onTouchEvent(parent, child, event);
}
private String getActionType(int eventType) {
StringBuilder builder = new StringBuilder();
if (eventType == MotionEvent.ACTION_DOWN)
builder.append(" DOWN");
else if ((eventType & MotionEvent.ACTION_UP) == MotionEvent.ACTION_UP)
builder.append(" UP");
else if ((eventType & MotionEvent.ACTION_CANCEL) == MotionEvent.ACTION_CANCEL)
builder.append(" CANCEL");
else if ((eventType & MotionEvent.ACTION_MOVE) == MotionEvent.ACTION_MOVE)
builder.append(" MOVE");
return builder.toString();
}
}
然后在项目中使用存储,这是一个示例代码: -
npm install --save google-cloud
这里的链接有完整的指南如何做google-cloud的东西。
const gcloud = require('google-cloud');
const storage = gcloud.storage({
projectId: //project id here,
keyFilename: //service account credentials here,
});
const storagebucket = storage.bucket('projectID.appspot.com');