I am trying to upload videos to my Flask app but I am getting errors every time i try to upload larger files
When making this request
curl --location --request POST 'http://192.168.1.217:5000/api/fileservice/0.1/files/upload_file' \
--form 'mime_type="video/mp4"' \
--form 'uuid="12345"' \
--form 'file=@"/home/sean/Videos/long.mp4"' \
--form 'file_name="my-great-file.mp4"''
I first receive a 308
response
192.168.1.217 - - [30/Oct/2022 13:23:17] "POST /api/fileservice/0.1/files/upload_file HTTP/1.1" 308 -
But after this I keep getting the following response back indicating that the remote side of the stream being written to has been closed.
POST http://192.168.1.217:5000/api/fileservice/0.1/files/upload_file
Error: write EPIPE
My Postman logs show this below the error
mime_type: "video/mp4"
uuid: "12345"
file: undefined
file_name: "my-great-file.mp4"
Interesting that the file is undefined. I assume because Flask isn't processing the large file properly.
Also there were a few occasions where it managed to hit the endpoint code before failing, and it appeared to fail here (based on the print statements that were/weren't outputted)
@blueprint.route("/files/upload_file/", methods=["POST"])
def upload_file():
"""Upload the file meta data and return the file upload location. Accepts a multipart/form-data request"""
print("test")
form_data = flask.request.form
file = flask.request.files["file"] ## FAILS HERE
print("file", file)
if not file:
raise Exception("No file provided")
byte_stream = file.read()
request = FileCreateRequest(
uuid=form_data["uuid"],
file_name=form_data["file_name"],
mime_type=form_data["mime_type"],
bytes=byte_stream,
)
result = flask.current_app.conns.file_service.create_file(request=request)
response = {}
response["file"] = vars(result.file)
response = flask.current_app.response_class(
response=json.dumps(response), status=200, mimetype="application/json"
)
return response
I think the issue is because the file is large (1.6MB) because requests like this with a much smaller mp4 file(390KB) work fine
curl --location --request POST 'http://192.168.1.217:5000/api/fileservice/0.1/files/upload_file' \
--form 'mime_type="video/mp4"' \
--form 'uuid="12345"' \
--form 'file=@"/home/sean/Videos/Peek 2022-10-30 10-08.mp4"' \
--form 'file_name="my-great-file.mp4"'
Any ideas on how i can solve this issue?