내 랩톱에서 로컬로 웹 애플리케이션을 실행하고 있습니다. 다음은 HTML에서 동영상을 가져와 Cloud Storage에 업로드하는 Python code 스니펫입니다.
@app.route('/' , methods=['POST', 'GET'])
def index():
if request.method== 'POST':
video= request.form['video']
video2= request.form['video2']
if not video:
flash('please upload your answer first')
if not video2:
flash('please upload your answer first')
else:
#store video to GCS
video_list= [video,video2]
for i in range(len(video_list)):
upload_video_to_gcs(video_list[i],i)
def upload_video_to_gcs(video,video_num):
# Setting credentials using the downloaded JSON file
client= storage.Client.from_service_account_json(json_credentials_path='sa-credentials.json')
# Creating bucket object
bucket= client.get_bucket('bucket_name')
# Name of the destination file in the bucket
gcs_file_name= "".join(("video","_",str(video_num)))
object_name_in_gcs_bucket= bucket.blob(gcs_file_name)
object_name_in_gcs_bucket.upload_from_filename(video)
return 1
동영상이 파이썬 파일과 같은 폴더에 있는 내 랩톱에서 로컬로 실행할 때 제대로 작동합니다. 그러나 이 웹 애플리케이션을 GCP Cloud Run에 배포했을 때(비디오가 더 이상 Python 파일의 동일한 폴더에 존재하지 않음) 아래 오류가 발생합니다.
FileNotFoundError: [Errno 2] No such file or directory: 'sample_video.mp4'
Cloud Run on GCP에서 호스팅되는 웹 서비스를 통해 비디오(내 노트북의 모든 위치에 있음)를 업로드하는 방법을 알고 있습니까?
- 답변 # 1
Python FileNotFoundError: [Errno 2] 해당 파일 또는 디렉터리가 없습니다.
오류는 종종 os 라이브러리에서 발생합니다. 이 오류는 존재하지 않는 파일이나 폴더에 액세스하려고 함을 알려줍니다. 이 오류를 수정하려면 프로그램에서 올바른 파일이나 폴더를 참조하고 있는지 확인하십시오.다음은 올바른 경로를 제공하여 수정된 것입니다.
게시 요청에서 비디오를 다운로드하는 code는 어디에 있습니까? 로컬에 저장하시나요?
guillaume blaquiere2022-02-02 06:21:14