Send Images through HTTPS Authorization #657
-
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
This automatically generated reply acts as a friendly reminder. Answers to your questions will most often come from the community, from developers like yourself. You will, from time to time, find that Axis employees answers some of the questions, but this is not a guarantee. Think of the discussion forum as a complement to other support channels, not a replacement to any of them. If your question remains unanswered for a period of time, please revisit it to see whether it can be improved by following the guidelines listed in Axis support guidelines. |
Beta Was this translation helpful? Give feedback.
-
HI @marsmith , Regarding: I am trying to use the Username and Password to uniquely identify this camera request.You can use the unique identifier here and parse the filename: |
Beta Was this translation helpful? Give feedback.
-
@vivekatoffice Great suggestion, but I would still like to transmit a password/passphrase with the request (along with a unique identifier). It seems odd to me there would be username/password field that are not used at all. I have also submitted a support ticket on this issue. Hopefully I will hear something back there. I appreciate your input. |
Beta Was this translation helpful? Give feedback.
-
Hi @marsmith , Install uvicorn to start FastAPI serverpip install uvicorn
app.py (Run using python app.py or uvicorn main:app --host 0.0.0.0 --port 8000)from fastapi import FastAPI, HTTPException, Depends, Request
from fastapi.security import HTTPBasic, HTTPBasicCredentials
from fastapi.responses import JSONResponse
from starlette.status import HTTP_401_UNAUTHORIZED
import os
app = FastAPI()
security = HTTPBasic()
# Hardcoded credentials
USER_DATA = {
"root": "pass"
}
UPLOAD_FOLDER = 'uploads'
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
def get_current_username(credentials: HTTPBasicCredentials = Depends(security)):
correct_username = credentials.username in USER_DATA
correct_password = correct_username and USER_DATA[credentials.username] == credentials.password
print("Username received from Axis Camera:",credentials.username)
print("Password received from Axis Camera:",credentials.password)
if not (correct_username and correct_password):
raise HTTPException(
status_code=HTTP_401_UNAUTHORIZED,
detail="Incorrect username or password",
headers={"WWW-Authenticate": "Basic"},
)
return credentials.username
@app.get("/upload")
async def get_upload_file(
username: str = Depends(get_current_username)
):
return JSONResponse(content={"message": "This is get method"}, status_code=200)
@app.post("/upload")
async def post_upload_file(request: Request, username: str = Depends(get_current_username)):
# Save file to local directory
return JSONResponse(
content={"message": "File uploaded successfully"},
status_code=200
)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000) Outputs: |
Beta Was this translation helpful? Give feedback.
With saving image on the local drive using the Filename from "Content-Disposition"*