タイトルの通り画像ファイルをFirebase Strageにupしようとすると、uploadボタンが反応せずに(index):50 Uncaught TypeError: firebase.storage is not a function
at uploadimage ((index):50)
at HTMLButtonElement.onclick ((index):30)
というエラーが出て困っています。
私としてはボタンが反応していないという問題なのでjs側の問題だと考えています。
原因または解決策をご存知の方はいらっしゃいませんか?
以下がコードです。
create.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Sign</title> <style> div{ position : absolute; right : 10px; top : 5px } </style> </head> <body> <div> <button type="button" onclick="location.href='{% url 'logout' %}'">Logout</button> </div> <H2>Create Reading Report</H2> <form action="/post_create/" method="post"> {% csrf_token %} Title : <input type="text" name="work" required><br><br> Predicting: <textarea rows="5" cols="40" name="progress" required></textarea> <br><br> Vizualizing: <input type="file" name="files[]" id="files" required> <input type="hidden" name="url" id="url"> <button type="button" onclick="uploadimage()">Upload</button><br><br> <input type="submit" value="Submit"> </form> </body> <script src="https://www.gstatic.com/firebasejs/6.4.0/firebase-app.js"></script> <script> var config = { apiKey: , authDomain: , databaseURL: , projectId:, storageBucket:, messagingSenderId:, appId: }; firebase.initializeApp(config); function uploadimage(){ var storage = firebase.storage(); var file = document.getElementById("files").files[0]; var storageRef = storage.ref(); var thisref = storageRef.child(file.name).put(file); thisref.on('state_changed',function(snapshot){ console.log("file uplaoded succesfully"); }, function(error) { alert("error"); }, function() { var downloadURL = thisref.snapshot.downloadURL; console.log("got url"); document.getElementById("url").value = downloadURL; alert("file uploaded successfully"); }); } </script> </html>
view.py
from django.shortcuts import render import pyrebase from django.contrib import auth config = { "apiKey": , "authDomain": , "databaseURL":, "projectId":, "storageBucket":, "messagingSenderId": , "appId": } firebase = pyrebase.initialize_app(config) authe = firebase.auth() database=firebase.database() def signIn(request): return render(request, "signIn.html") def postsign(request): email=request.POST.get('email') password = request.POST.get("password") try: user = authe.sign_in_with_email_and_password(email,password) except: message="invalid credentials" return render(request,"signIn.html",{"errorMessg":errorMessage}) print(user['idToken']) session_id=user['idToken'] request.session['uid']=str(session_id) return render(request, "welcome.html",{"e":email}) def logout(request): auth.logout(request) return render(request,'signIn.html') def signUp(request): return render(request,"signup.html") def postsignup(request): name=request.POST.get('name') email=request.POST.get('email') password=request.POST.get('password') try: user=authe.create_user_with_email_and_password(email,password) except: errorMessage="Unable to create account try again" return render(request,"signup.html",{"errorMessg":errorMessage}) uid = user['localId'] data={"name":name,"status":"1"} database.child("users").child(uid).child("details").set(data) return render(request,"signIn.html") def create(request): return render(request,'create.html') def post_create(request): import time from datetime import datetime, timezone import pytz tz= pytz.timezone('Asia/Tokyo') time_now= datetime.now(timezone.utc).astimezone(tz) millis = int(time.mktime(time_now.timetuple())) print("mili"+str(millis)) work = request.POST.get('work') progress =request.POST.get('progress') url = request.POST.get('url') idtoken= request.session['uid'] a = authe.get_account_info(idtoken) a = a['users'] a = a[0] a = a['localId'] print("info"+str(a)) data = { "work":work, 'progress':progress, 'url':url } database.child('users').child(a).child('reports').child(millis).set(data) name = database.child('users').child(a).child('details').child('name').get().val() return render(request,'welcome.html', {'e':name}) def check(request): import datetime idtoken = request.session['uid'] a = authe.get_account_info(idtoken) a = a['users'] a = a[0] a = a['localId'] timestamps = database.child('users').child(a).child('reports').shallow().get().val() lis_time=[] for i in timestamps: lis_time.append(i) lis_time.sort(reverse=True) print(lis_time) work = [] for i in lis_time: wor=database.child('users').child(a).child('reports').child(i).child('work').get().val() work.append(wor) print(work) date=[] for i in lis_time: i = float(i) dat = datetime.datetime.fromtimestamp(i).strftime('%H:%M %d-%m-%Y') date.append(dat) print(date) comb_lis = zip(lis_time,date,work) name = database.child('users').child(a).child('details').child('name').get().val() return render(request,'check.html',{'comb_lis':comb_lis,'e':name}) def post_check(request): import datetime time = request.GET.get('z') idtoken = request.session['uid'] a = authe.get_account_info(idtoken) a = a['users'] a = a[0] a = a['localId'] work =database.child('users').child(a).child('reports').child(time).child('work').get().val() progress =database.child('users').child(a).child('reports').child(time).child('progress').get().val() img_url = database.child('users').child(a).child('reports').child(time).child('url').get().val() print(img_url) i = float(time) dat = datetime.datetime.fromtimestamp(i).strftime('%H:%M %d-%m-%Y') name = database.child('users').child(a).child('details').child('name').get().val() return render(request,'post_check.html',{'w':work,'p':progress,'d':dat,'e':name,'i':img_url})
回答1件
あなたの回答
tips
プレビュー