I want to store captured images to my php website, I am using the following code and I have tried different variations and solutions nothing seems to work I have also looked over the internet for over 3 days looking for a solution and I found nothing.
How can I upload captured photos to a php website?
<code>
import urequests
import camera
from machine import Pin
import network
import urequests
import machine
import time
machine.freq(240000000)
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
time.sleep(1)
if sta_if.isconnected():
sta_if.disconnect()
print (f'started in the connected state, but now disconnected')
time.sleep(1)
sta_if.connect('dlink-M961-2.4G-a176', 'skmfu47667')
time.sleep(1)
print(sta_if.isconnected())
else:
print (f'started in the disconnected state')
print(sta_if.active())
sta_if.connect('dlink-M961-2.4G-a176', 'skmfu47667')
print(sta_if.isconnected())
gc.collect()
gc.mem_free()
flash = Pin(4, Pin.OUT)
time.sleep(1)
camera.init(0, format=camera.JPEG, fb_location=camera.PSRAM)
time.sleep(1)
camera.quality(12)
camera.framesize(9)
flash.value(1)
time.sleep(1)
gc.collect()
gc.mem_free()
buf = camera.capture()
flash.value(0)
file = open("/esp32-1.jpg","wb")
file.write(buf)
file.close()
file = open("/esp32-1.jpg","rb")
r = urequests.request("POST", "https://x.x.net/python/image.php", json={"name":"esp32.jpg","photo":file})
print(r.text)
</code>
<code>
import urequests
import camera
from machine import Pin
import network
import urequests
import machine
import time
machine.freq(240000000)
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
time.sleep(1)
if sta_if.isconnected():
sta_if.disconnect()
print (f'started in the connected state, but now disconnected')
time.sleep(1)
sta_if.connect('dlink-M961-2.4G-a176', 'skmfu47667')
time.sleep(1)
print(sta_if.isconnected())
else:
print (f'started in the disconnected state')
print(sta_if.active())
sta_if.connect('dlink-M961-2.4G-a176', 'skmfu47667')
print(sta_if.isconnected())
gc.collect()
gc.mem_free()
flash = Pin(4, Pin.OUT)
time.sleep(1)
camera.init(0, format=camera.JPEG, fb_location=camera.PSRAM)
time.sleep(1)
camera.quality(12)
camera.framesize(9)
flash.value(1)
time.sleep(1)
gc.collect()
gc.mem_free()
buf = camera.capture()
flash.value(0)
file = open("/esp32-1.jpg","wb")
file.write(buf)
file.close()
file = open("/esp32-1.jpg","rb")
r = urequests.request("POST", "https://x.x.net/python/image.php", json={"name":"esp32.jpg","photo":file})
print(r.text)
</code>
import urequests
import camera
from machine import Pin
import network
import urequests
import machine
import time
machine.freq(240000000)
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
time.sleep(1)
if sta_if.isconnected():
sta_if.disconnect()
print (f'started in the connected state, but now disconnected')
time.sleep(1)
sta_if.connect('dlink-M961-2.4G-a176', 'skmfu47667')
time.sleep(1)
print(sta_if.isconnected())
else:
print (f'started in the disconnected state')
print(sta_if.active())
sta_if.connect('dlink-M961-2.4G-a176', 'skmfu47667')
print(sta_if.isconnected())
gc.collect()
gc.mem_free()
flash = Pin(4, Pin.OUT)
time.sleep(1)
camera.init(0, format=camera.JPEG, fb_location=camera.PSRAM)
time.sleep(1)
camera.quality(12)
camera.framesize(9)
flash.value(1)
time.sleep(1)
gc.collect()
gc.mem_free()
buf = camera.capture()
flash.value(0)
file = open("/esp32-1.jpg","wb")
file.write(buf)
file.close()
file = open("/esp32-1.jpg","rb")
r = urequests.request("POST", "https://x.x.net/python/image.php", json={"name":"esp32.jpg","photo":file})
print(r.text)