[英]Video Upload in Cloud Run Flask Application is Giving No such file or directory
I am having a web application running locally on my laptop.我有一个 web 应用程序在我的笔记本电脑上本地运行。 Below is the python code snippet that takes the video from the HTML and uploads it to Cloud Storage:下面是 python 代码片段,它从 HTML 获取视频并将其上传到 Cloud Storage:
@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
It is working fine when running it locally on my laptop, in which the video is located in the same folder as the python file.在我的笔记本电脑上本地运行它时工作正常,其中视频与 python 文件位于同一文件夹中。 However, when I deployed this web application on GCP Cloud Run(the video is no more existing in the same folder of the python file), I am getting the below error:但是,当我在 GCP Cloud Run 上部署此 web 应用程序时(该视频不再存在于 python 文件的同一文件夹中),我收到以下错误:
FileNotFoundError: [Errno 2] No such file or directory: 'sample_video.mp4'
Do you have any idea how to upload the video(existing anywhere on my laptop) through the web service hosted on Cloud Run on GCP.您是否知道如何通过 GCP 上 Cloud Run 上托管的 web 服务上传视频(存在于我笔记本电脑上的任何位置)。
The Python FileNotFoundError: [Errno 2] No such file or directory
error is often raised by the os library. Python FileNotFoundError: [Errno 2] No such file or directory
错误通常由 os 库引发。 This error tells you that you are trying to access a file or folder that does not exist.此错误告诉您您正在尝试访问不存在的文件或文件夹。 To fix this error, check that you are referring to the right file or folder in your program.要修复此错误,请检查您是否在程序中引用了正确的文件或文件夹。
Here is a similar case that was fixed by providing the correct path.这是通过提供正确路径修复的类似情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.