Posts

Showing posts from February, 2023

Thread create in Android

  In Android, you can create a new thread to run tasks in parallel with the main thread. There are several ways to create threads in Android: Extending the Thread class: java Copy code class MyThread extends Thread {  @Override public void run () {  // Your code to run in the new thread    }  }  // To start the thread:   MyThread thread = new MyThread ();  thread.start(); Implementing the Runnable interface: java Copy code class MyRunnable implements Runnable { @Override   public void run ()   { // Your code to run in the new thread    }  } // To start the thread:   Thread thread = new Thread ( new MyRunnable ());  thread.start(); Using the Executor framework: java Copy code Executor executor = Executors.newSingleThreadExecutor();  executor.execute( new Runnable ()  {  @Override   public void run ()   {  // Your code to run in the new thread ...

File Post FastApi in Python

  To create a directory and save a video in a FastAPI application in Python, you can use the built-in os module. Here's an example: python import os import uvicorn as uvicorn from fastapi import FastAPI , UploadFile , File , Header app = FastAPI() @app.post ( "/video" ) async def save_video (file: UploadFile): # Get the file name from the header file_name = file.filename # Save the file to disk with open ( f"/tmp/ { file_name } " , "wb" ) as f: f.write( await file.read()) return { "message" : "Video saved successfully" } @app.post ( "/video1" ) async def post_video (video: UploadFile): return { "video_filename" : video.filename} @app.post ( "/video3" ) async def post_video (video: UploadFile): directory = "videos" if not os.path.exists(directory): os.makedirs(directory) video_path = os.path.join(directory , video.filename) with open (vid...