Jan-24-2022, 04:59 AM
(This post was last modified: Jan-24-2022, 08:02 AM by Gribouillis.)
I am working on a fish map solution that is a container for great info, however i am having trouble getting some media to it because when I upload video via html <form> in python3 the output is blank....however the length of the video is coded. Any Help after digesting the code?
specifically,
form = cgi.FieldStorage()
file = form.getvalue('videofile')
print (file)
with open('/var/www/fishvid/output.mp4', 'wb') as bfile:
bfile.write(file)
bfile.close()
print ('The video was successfully saved')
<url snipped>
I have a test script made that works to test..
test.py
<url snipped>
fishmap.py
specifically,
form = cgi.FieldStorage()
file = form.getvalue('videofile')
print (file)
with open('/var/www/fishvid/output.mp4', 'wb') as bfile:
bfile.write(file)
bfile.close()
print ('The video was successfully saved')
<url snipped>
I have a test script made that works to test..
test.py
#!/usr/bin/env python3 # -*- coding: UTF-8 -*- # enable debugging import cgitb cgitb.enable() import cgi import os #html in python print ('''Content-Type: text/html''') # HTML is following print print #12 returns in the next bracket print (''' <html><head> <title>J^2</title> <meta name="description" content="test" /> <meta http-equiv="content-type" content="text/html" /> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <style> body {background: #1339de;} div#container { background: black; width: 50%; margin: 100px auto; color: white; border-radius: 1em; width: 1400px; height: 1125px; overflow:hidden; /* if you don't want a scrollbar, set to hidden */ overflow-x:hidden; /* hides horizontal scrollbar on newer browsers */ /* resize and min-height are optional, allows user to resize viewable area */ -webkit-resize:vertical; -moz-resize:vertical; resize:vertical; // min-height:1600px; } </style> <body><div id="main"><div id="site_content"><div id="content"> <h1>Test</h1> <form enctype='multipart/form-data' action='test.py' method='POST'><p>Location Video</p><p>Upload File: <input type = 'file' name= 'videofile' /></p><input type='submit' value='Upload' /></form> </div></div></div></body> </html>''') form = cgi.FieldStorage() file = form.getvalue('videofile') print (file) with open('/var/www/fishvid/output.mp4', 'wb') as bfile: bfile.write(file) bfile.close() print ('The video was successfully saved')The major point is to have video upload to my webpage.
<url snipped>
fishmap.py
#!/usr/bin/env python3 # -*- coding: UTF-8 -*- # enable debugging import cgitb cgitb.enable() import cgi from datetime import date, datetime, timedelta import csv2 as csv import os import base64 #html in python print ('''Content-Type: text/html''') # HTML is following print print #12 returns in the next bracket print (''' <html><head> <title>J^2</title> <meta name="description" content="fish fishing map with Doppler Radar Map" /> <meta http-equiv="content-type" content="text/html" /> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <style> body {background: #1339de;} div#container { background: black; width: 50%; margin: 100px auto; color: white; border-radius: 1em; width: 1400px; height: 1125px; overflow:hidden; /* if you don't want a scrollbar, set to hidden */ overflow-x:hidden; /* hides horizontal scrollbar on newer browsers */ /* resize and min-height are optional, allows user to resize viewable area */ -webkit-resize:vertical; -moz-resize:vertical; resize:vertical; // min-height:1600px; } div#containerlil { background: black; width: 50%; margin: 100px auto; color: white; border-radius: 1em; width: 320px; height: 240px; overflow:hidden; /* if you don't want a scrollbar, set to hidden */ overflow-x:hidden; /* hides horizontal scrollbar on newer browsers */ /* resize and min-height are optional, allows user to resize viewable area */ -webkit-resize:vertical; -moz-resize:vertical; resize:vertical; // min-height:640px; } </style> <body><div id="main"><div id="site_content"><div id="content"> <h1>Doppler Map with Fishing Report!!!</h1> </div></div></div></body> <script type="text/javascript" > function go() { var m3=document.getElementsByName("c"); var m4=document.getElementsByName("d"); window.location.href = "https://lftr.biz/cgi-bin/fishmap.py" + m3(0).value+"+"+ m4(0).value; } </script> <script type="text/javascript" > function go2() { var m3=document.getElementsByName("e"); var m4=document.getElementsByName("f"); window.location.href = "https://lftr.biz/cgi-bin/fishmap.py" + m3(0).value+"+"+ m4(0).value; } </script> </html>''') print (''' <h4>Alert to a new fishing location...!!!!</h4> <form action="https://lftr.biz/cgi-bin/fishmap.py" onsubmit="go();"> Latitude (xxx.xxxx/-xxx.xxxx): <input type="text" name="c" value= "33.3866412"><br> Longitude (xxx.xxxx/-xxx.xxxx): <input type="text" name="d" value= "-118.4734779"><br> <input type="submit" value="Submit"> </form> ''') #lat,lng,report tuple as list (commented out bc i am using a local csv file so as to WRITE reports to current locations) #latlng = [(33.5987, -117.8826, ), (36.4147885,-118.9277509, ), (36.0765497,-118.9106086, ), (37.0396,-119.6483, ), (33.5901046, -117.870014, ), (33.5985056, -117.9033164, ), (33.6074678, -117.9309998, ), (33.6531, -118.0061, ), (33.7419998, -118.1875496, ), (34.4986553, -118.6108158, ), (34.2906126, -117.3599411, ), (34.565518, -114.3949421, ), (34.5133492, -114.3702769, ), (34.4548, -114.3755, ), (34.4495, -114.3724, ), (34.4494, -114.3712, )] # open and read lat,lng,report tuple as list in local .csv file = open("/var/www/cgi-bin/fishloclist.csv", "r") csv_reader = csv.reader(file) #make csv content a python3 list loc = [] for row in csv_reader: loc.append(row) #Reload information for subbmitting reports #pulls the variable values from the improved url #saves the report to the list #try or else just load with out updating via url when the url is standard form = cgi.FieldStorage() try: lat = float(form.getvalue("c")) lng = float(form.getvalue("d")) coord = (lat,lng,'') loc.append(coord) with open('/var/www/cgi-bin/fishloclist.csv', 'w', newline='') as f: writer = csv.writer(f) writer.writerows(loc) print ('location submited'+str(loc[-1])) except: print ('') try: report = str(form.getvalue("e")) locnum = int(form.getvalue("f")) loc[locnum].append(report) with open('/var/www/cgi-bin/fishloclist.csv', 'w', newline='') as f: writer = csv.writer(f) writer.writerows(loc) print ('report submited'+str(loc[locnum])) except: print ('') try: file = form.getvalue('videofile') # file = form[videofile] decodedfile = base64.b64decode(decodedfile) locnum = int(form.getvalue("f")) os.remove('fishvid/output'+str(locnum)+'.mp4') with open('fishvid/output'+str(locnum)+'.mp4', 'rb') as wfile: wfile.write(file) wfile.close() print ('The video was successfully saved') except: print ('') ###the next print section hosts ARCGIS API for JAVASCRIPT (in python) ##this happens with some integration to python variabes #also the loop will read how many locations by length of list then pull the tuple parts and use them seperately for each point with popups is iterated on one graphics layer print ('''<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" /><title>ArcGIS API for JavaScript 4.22</title> <style> html, body, #viewDiv { padding: 0; margin: 0; height: 100%; width: 100%; } </style> <link rel="stylesheet" href="https://js.arcgis.com/4.22/esri/themes/light/main.css" /> <script src="https://js.arcgis.com/4.22/"></script> <script>require(["esri/Map", "esri/views/SceneView", "esri/layers/SceneLayer","esri/layers/WMSLayer","esri/widgets/BasemapToggle","esri/layers/TileLayer","esri/layers/VectorTileLayer","esri/layers/GraphicsLayer","esri/layers/CSVLayer","esri/widgets/Search","esri/widgets/Locate","esri/widgets/Track","esri/Graphic","esri/layers/FeatureLayer", "esri/widgets/Editor", "esri/popup/content/AttachmentsContent","esri/popup/content/TextContent"], (Map, SceneView, SceneLayer,WMSLayer,BasemapToggle,TileLayer,VectorTileLayer,GraphicsLayer,CSVLayer,Search,Locate,Track,Graphic, FeatureLayer, Editor, AttachmentsContent, TextContent) => { const layer = new WMSLayer({url: "https://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi", sublayers: [{name: "nexrad-n0r-900913"}], refreshInterval:.25}); let map = new Map({ basemap: {baseLayers:[layer, new TileLayer({url: "https://services.arcgisonline.com/arcgis/rest/services/World_Terrain_Base/MapServer"}), new VectorTileLayer({portalItem: {id: "273bf8d5c8ac400183fc24e109d20bcf"}, blendMode: "multiply"})]}, ground: "world-elevation",}); let view = new SceneView({container: "viewDiv", map: map, camera: {position: {x: '''+str(-117)+' , y:'+str(34)+''' , z: 12500000}, tilt: 0},}); const locate = new Locate({ view: view, useHeadingEnabled: false, goToOverride: function(view, options) { options.target.scale = 1500; return view.goTo(options.target); } }); view.ui.add(locate, "top-left"); const track = new Track({ view: view,graphic: new Graphic({symbol: {type: "simple-marker",size: "12px",color: "green",outline: {color: "#efefef", width: "1.5px"}}}),seHeadingEnabled: true}); view.ui.add(track, "top-left"); const search = new Search({view: view}); view.ui.add(search, "top-right"); const toggle = new BasemapToggle({view: view, nextBasemap: "hybrid"}); view.ui.add(toggle, "top-right"); const graphicsLayer = new GraphicsLayer(); map.add(graphicsLayer );''') length = len(loc) for x in range(length): report = str(loc[x][-1]) latitude = str(loc[x][0]) longitude = str(loc[x][1]) ####very long print statement below that makes the points w popups and takes reports print (''' var template'''+str(x)+''' = {title: 'Location:''' +str(x)+''' - Coordinates: ''' +latitude+' , '+longitude+' Report: '+report+ ''' ', content: function(){ var report = document.createElement("div"); report.className = "myClass"; report.innerHTML = "<h2>Location Video</h2><div id='containerlil'><video width='320' height='240' controls autoplay src='/fishvid/output'''+str(x)+'''.mp4' type='video/mp4'></video></div><h2>SmashUpVideo</h2><div id='containerlil'><video width='320' height='240' controls autoplay src='/fastfish.mp4' type='video/mp4'></video></div> <h1>Submit A New Fishing Report</h1><form action='https://lftr.biz/cgi-bin/fishmap.py' onsubmit='go2();'>Enter Report: <input type='text' name='e' value= 'date, observation, tips & tricks'><br><input name ='f' value= '''+str(x)+''' type='hidden'><input type='submit' value='Submit'> </form> <form enctype='multipart/form-data' action='fishmap.py?f= '''+str(x)+''' ' method='POST'><p>Location Video</p><p>Upload File: <input type = 'file' name= 'videofile' /></p><input type='submit' value='Upload' /></form> "; return report; } }; const point'''+str(x)+''' = {type: "point", x: ''' +longitude+ ''' , y: ''' +latitude+ ''' , z: 4010}; const markerSymbol'''+str(x)+''' = {type: "simple-marker", color: [226, 119, 40], outline: {color: [255, 255, 255], width: 4}}; const pointGraphic'''+str(x)+''' = new Graphic({geometry: point'''+str(x)+''' , popupTemplate: template'''+str(x)+''' , symbol: markerSymbol'''+str(x)+'''}); graphicsLayer.add(pointGraphic'''+str(x)+''' ); ''') print (''' }); </script></head><body><div id="container"><div id="viewDiv"></div></div></body></html>''') #############################################################################
Gribouillis write Jan-24-2022, 08:02 AM:
Url snipped because it caused a security warning from my browser. Please read the help section about what not to include in a post.
Url snipped because it caused a security warning from my browser. Please read the help section about what not to include in a post.