LA: Convert email attachment to PDF fails: "The file is invalid"

Jurgen Verhelst 331 Reputation points
2021-01-06T07:28:17.877+00:00

Hi guys

We want to store email attachments (only if xlsx) as PDF files on a FTP server

Am I right to use the 'id of the attachment' as the file input of the convert step? it seems that is the content, not the file id (see error at the bottom)

here is the LA and the second screenshot is the error

53816-screenshot-2021-01-06-082632.png

error

53942-screenshot-2021-01-06-082029.png

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,557 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. MayankBargali-MSFT 70,941 Reputation points Moderator
    2021-01-07T04:53:34.43+00:00

    Hi @Jurgen Verhelst

    The error is expected as the action "Convert File" could not find the file ID (AAMkADcONm.....) in your onedrive.
    Convert File has two input parameters file (file ID in onedrive) and target type. The onedrive connector is used for access and manage files in onedrive.

    The workaround would create the file first using Get Attachment Output before converting and the flow will be:
    Get Attachment Output --> Create file --> Convert file --> Create File (FTP server) --> Delete File

    54160-image.png

    54168-image.png

    You can modify the hardcoded value according to your need and I hope the above helps you.
    Feel free to get back to me if you need any assistance.

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.


  2. Jurgen Verhelst 331 Reputation points
    2021-01-11T22:38:31.173+00:00

    Hi @MayankBargali-MSFT ,

    Nice to see you helping me out again,

    I followed your steps, and I understand what your suggestion is, but the for each step keeps on failing without much information, no errorcode, just timeout on the "convert file" step as I do see the excel file in onedrive

    55552-screenshot-2021-01-11-232531.png

    Now, it was maybe because I there is a small jpg added to every mail in our environment so I added a condition to only account for excel files. but still it fails

    55435-screenshot-2021-01-11-233038.png

    this is how the flow looks like

    I also tried with new files, maybe the Create file or the convert file step is not able to overwrite an existing file but I see the excel file being overwriten as I hope it would. The PDF file newer gets created.


  3. Jurgen Verhelst 331 Reputation points
    2021-01-17T23:03:58.62+00:00

    I removed the condition step (I am testing with plain emails not containing any formatting picture attachments) and the xslx is dropped in the ondedrive ok, the PDF get created and dropped in the ftp server but are not able to be opened with a pdf reader nor edge browser... the file size is OK (not 0kb) and opening in notepad++ reveils they contain the following:

    0000000206 65535 f
    0000000207 65535 f
    0000000208 65535 f
    0000000209 65535 f
    0000000210 65535 f
    0000000000 65535 f
    0000005429 00000 n
    0000005923 00000 n
    0000046064 00000 n
    0000049384 00000 n
    0000049430 00000 n
    trailer
    <</Size 216/Root 1 0 R/Info 3 0 R/ID[<856410437B5B48499E0986D394975B7A><856410437B5B48499E0986D394975B7A>] >>
    startxref
    50045
    %%EOF
    xref
    0 0
    trailer
    <</Size 216/Root 1 0 R/Info 3 0 R/ID[<856410437B5B48499E0986D394975B7A><856410437B5B48499E0986D394975B7A>] /Prev 50045/XRefStm 49430>>
    startxref
    54523
    %%EOF
    

    I checked this on another working PDF and it seems that is the part every pdf had at the end of the file. but the generated PDF's only contain that bit which suggests it is creating an empty pdf...

    So it must be that the "File" paramerer in the "Convert" step is not working as it is not getting the file+content creates with the "create file" (Ondedrive) action...

    This is what the convert step gets as input:

    {
        "method": "get",
        "queries": {
            "type": "PDF"
        },
        "path": "/datasets/default/files/b%2521Vyzyn2JgHEa8EqjBGElckAhnXkAKID1EhbyuENRkY22kL_UyxBhCRZPgWJZjTnYR.01AG4JVHOS4DWRSFSGWVBL2II6CYONHAZL/convert",
        "host": {
            "connection": {
                "name": "/subscriptions/b8a8a9f3-7d13-4541-af77-f5e97487ad90/resourceGroups/SPO/providers/Microsoft.Web/connections/onedriveforbusiness"
            }
        }
    }
    

    So maybe 'id' is not the right parameter to parse. But when I look what else besides the smal 'id' nothing else looks right to select, even when clicking "see more"

    • Blob metadata
    • Display name
    • Etag
    • file locator
    • id
    • Last Modified time
    • last modified by
    • media type
    • List item
    • name
    • name without extension
    • path
    • is folder
    • size

    So 'id' seems to be right. how can I check what is actually

    0 comments No comments

  4. Jurgen Verhelst 331 Reputation points
    2021-01-17T23:23:17.903+00:00

    Hi @MayankBargali-MSFT ,

    As in the message I wrote just before there are other parameters than the 'id' from the Create file action. we already established the files created there are good xlsx files so I tried using other variables to use as the 'File' parameter in the convert action/

    So I tried with 'File locator' and then the flow runs OK but it contains the same empty pdf file (containing just the lines any pdf file has at the end)

    here are the run history of tonight, the 'failed' ones are with the small 'id', the 'succeeded' once are with 'file locator' but render an enmpty pdf

    Cancelled
    18/1/2021 00:17
    08585906814655039505278043738CU58

    1. 02 Minutes
      Cancelled
      18/1/2021 00:14
      08585906816445810825741195649CU61
    2. 6 Minutes
      Succeeded
      18/1/2021 00:13
      08585906816569587495169362761CU19
      170 Milliseconds
      Cancelled
      18/1/2021 00:12
      08585906817231138339241022073CU27
    3. 14 Minutes
      Cancelled
      18/1/2021 00:11
      08585906818145718487541830110CU16
    4. 09 Seconds
      Succeeded
      18/1/2021 00:10
      08585906818294389988121983811CU61
      130 Milliseconds
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.