简体   繁体   English

Cloud Run 中的视频上传 Flask 应用程序正在提供 没有此类文件或目录

[英]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.

相关问题 如何在没有 BlobStore 的情况下从 Flask 表单将视频文件直接上传到 Cloud Storage? - How to upload a video file directly to Cloud Storage from a Flask form without BlobStore? Flask在文件上传时给出错误400 - Flask giving error 400 on file upload Flask Web应用程序无法上传文件 - Flask web application can't upload file 如何使用 python 请求将文件上传到 flask 应用程序 - How to upload file to flask application with python requests Flask 图片无法上传(FileNotFoundError: [Errno 2] No such file or directory) - Flask image cant upload (FileNotFoundError: [Errno 2] No such file or directory) Flask 应用程序中的 Opencv 视频 - Opencv video in Flask application Flask应用程序文件上传-获取文件内容时出错 - Flask Application File Upload - Error while getting contents of file 使用 Python 将文件上传到 Google Cloud Storage Bucket 子目录 - Upload File to Google Cloud Storage Bucket Sub Directory using Python flask 运行给我 ModuleNotFoundError - flask run giving me ModuleNotFoundError Flask:如何使用 upload_blob 将用户文件上传到 Google Cloud Storage - Flask: How to upload a user file into Google Cloud Storage using upload_blob
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM