Search code examples
c#filefilestreamdeepl

Deepl API TranslateDocumentAsync cannot convert from FileStream to FileInfo C# librabry


I use the C# library to connect to the DeepL API. According to the documentation, you can use the TranslateDocumentAsync method for document translation. This method should be able to accept the FileInfo and Stream parameters.

await _translator.TranslateDocumentAsync(
      sourceFileStream,
      targetFileStream,
      "DE",
      "FR");

However, when I transfer a file that I have saved as a FileStream, I always get the error

Cannot convert from System.IO.FileStream to System.IO.FileInfo

How can I pass a Stream/FileStream as a parameter?


Solution

  • The overload accepting Stream has an additional second argument: string inputFilename. This is used to tell the DeepL API the input file type; actually the input file extension is sufficient, for example ".pdf".

    The description in the readme is misleading. I'm a maintainer, so I'll correct the readme description.