dify icon indicating copy to clipboard operation
dify copied to clipboard

ERROR: missing file upload_file_id

Open killpanda opened this issue 1 year ago • 1 comments

Self Checks

Dify version

0.5.2 and other older versions

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

  1. create a text generator type app
  2. use the gpt-4-vision-preview model, and enable the Vision feature
  3. when using app, select uploading a file choose a file, and click run. If the file does not finish uploading, it will show an error.
image

✔️ Expected Behavior

show a friendly message, like waiting for upload finished.

❌ Actual Behavior

show error missing file file_upload_id

killpanda avatar Jan 31 '24 16:01 killpanda

🤖

Thank you for bringing this issue to our attention. It seems like the error is occurring because the system is trying to process the file before it has finished uploading. To prevent this, we can add a check to ensure that the file has finished uploading before proceeding with the rest of the code.

Here's how you can modify the FileApi class to include this check:

class FileApi(AppApiResource):

    @marshal_with(file_fields)
    def post(self, app_model, end_user):

        file = request.files['file']
        user_args = request.form.get('user')

        if end_user is None and user_args is not None:
            end_user = create_or_update_end_user_for_user_id(app_model, user_args)

        # check file
        if 'file' not in request.files:
            raise NoFileUploadedError()

        if not file.mimetype:
            raise UnsupportedFileTypeError()

        if len(request.files) > 1:
            raise TooManyFilesError()

        try:
            upload_file = FileService.upload_file(file, end_user)
            # Check if the file has finished uploading
            if not upload_file.is_uploaded:
                raise services.errors.file.FileNotUploadedError()
        except services.errors.file.FileTooLargeError as file_too_large_error:
            raise FileTooLargeError(file_too_large_error.description)
        except services.errors.file.UnsupportedFileTypeError:
            raise UnsupportedFileTypeError()
        except services.errors.file.FileNotUploadedError:
            raise FileNotUploadedError()

        return upload_file, 201

In this code, FileNotUploadedError is a hypothetical error that you would need to define in your services.errors.file module. This error should be raised when the file has not finished uploading. The is_uploaded attribute is also hypothetical and would need to be implemented in your upload_file object to indicate whether the file has finished uploading.

Please note that this is a suggested solution and might need some adjustments to fit into your specific use case. If you have any further questions or need more clarification, feel free to ask.

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

dosubot[bot] avatar Jan 31 '24 16:01 dosubot[bot]

Fixed with https://github.com/langgenius/dify/pull/2388.

iamjoel avatar Feb 05 '24 05:02 iamjoel