Skip to content

File parameters not interpreted as files  #60

Closed

Description

@kostas-jonauskas

There is a bug in the library when passing multiple files to the converter. For example, DOCX to Compare conversion takes two files as parameters: File and CompareFile. The File parameter is interpreted as a file and sent to CARA as a file object. My guess is that the CompareFile is sent as a plain string (path to file) rather than the file itself. Conversion results in the following error:

 data: {
      Code: 5008,
      Message: 'Unable to access the file. Call failed with status code 500 (Internal Server Error). Remote file C:/Projects/stuff/Test projects/ConvertAPI NodeJs/file-2.docx'
 }

Code snippet to replicate the issue:

const convertapi = require('convertapi')(secret);
convertapi.convert('compare', {
	File: '/path/to/file-1.docx',
	CompareFile: '/path/to/file-2.docx',
	}, 'docx').then(function(res) {
		console.log(res);
})

Please note that there might be more conversions that accept multiple files as parameters, for example PDF watermark overlay (https://www.convertapi.com/pdf-to-watermark-overlay), so hardcoding the logic based on property name is not a good idea.

Activity

  1. tomasr78 commented on Jul 10, 2023

    @tomasr78
    Contributor

    The current implementation doesn't have a property type to indicate what parameter type it is, File or String param.
    I suggest doing a string comparison. If the property name is File or ends with *File it should consider as a File parameter.

    This is a small list of File parameters in ConvertAPI, just an example to show that all file parameters end with a File string in the name.

    File 
    CompareFile
    OverlayFile
    
  2. laurynas-convertapi commented on Jul 15, 2023

    @laurynas-convertapi
    Contributor

    @tomasr78 matching the end of the string with File sounds like a simple solution, but there are params like StoreFile - it would match the expression. Is it ok to make the exception for StoreFile or rather make a list of file params, like File, CompareFile, OverlayFile? Also are there more cases of Files (multiple files) params?

  3. tomasr78 commented on Jul 15, 2023

    @tomasr78
    Contributor

    @laurynas-baltsoft It would be best to make an exception for the StoreFile parameter, as converters with File parameters may grow over time and we can't know all of them now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions