最近の検索


最近の検索はありません

Marcus Dawideit's Avatar

Marcus Dawideit

参加日2023年1月19日

·

前回のアクティビティ2024年5月27日

フォロー中

0

フォロワー

0

合計アクティビティ

7

投票

0

受信登録

3

アクティビティの概要

さんの最近のアクティビティ Marcus Dawideit

Marcus Dawideitさんが投稿を作成しました:

投稿 Developer - Zendesk APIs

Good morning,

 

I have a strange behaviour when uploading files via API. If I use Zendesk own ZAF client for my request then the uploaded PDF is corrupt, if the upload is made via a JQuery request, for example, then the file is OK.

 

Source with Client.Request / Corrupt Upload File

async function fetchFile(fileUrl, fileName, filecontentType) {
    try {

        const blobResponse = await $.ajax({
            url: fileUrl,
            method: 'GET',
            xhrFields: {
                responseType: 'blob'
            }
        });
        var formData = new FormData();
        formData.append('file', blobResponse, fileName);

        const options = {
            url: '/api/v2/uploads.json?filename=' + encodeURIComponent(fileName),
            type: 'POST',
            processData: false,
            contentType: false,
            headers: {
                'Content-Type': filecontentType
            },
            data: formData

        };

        const response = await client.request(options);

        if (typeof response === 'string') {
            responseData = JSON.parse(response);
        } else {
            responseData = response;
        }

        return responseData.upload.token;

    } catch (error) {
        console.error('Fehler beim Senden der Anfrage an den Server:', error);
        if (error.response) {
            console.error('Response data:', error.response.data);
        }
    }
}

 

The same source with Upload via Jquery / Upload File OK

async function fetchFile(fileUrl, fileName, filecontentType) {
    try {

        const blobResponse = await $.ajax({
            url: fileUrl,
            method: 'GET',
            xhrFields: {
                responseType: 'blob'
            }
        });
        var formData = new FormData();
        formData.append('file', blobResponse, fileName);

        const options = {
            url: 'https://.zendesk.com/api/v2/uploads.json?filename=' + encodeURIComponent(fileName),
            type: 'POST',
            processData: false,
            contentType: false,
            headers: {
                'Content-Type': filecontentType,
                'Authorization': 'Basic ' + btoa(zendeskEmail + '/token:' + zendeskApiToken)
            },
            data: formData

        };

        const response = await $.ajax(options);

        if (typeof response === 'string') {
            responseData = JSON.parse(response);
        } else {
            responseData = response;
        }

        return responseData.upload.token;

    } catch (error) {
        console.error('Fehler beim Senden der Anfrage an den Server:', error);
        if (error.response) {
            console.error('Response data:', error.response.data);
        }
    }
}

 

Does anyone have any idea what the problem might be? I am grateful for the advice !

 

Thanks in advance,

 

Marcus

投稿日時:2024年5月27日 · Marcus Dawideit

0

フォロワー

1

投票

1

コメント


Marcus Dawideitさんがコメントを作成しました:

コミュニティのコメント Developer - Zendesk APIs

Hello, 

are there any new findings? I am facing the same problem, all files except PDF are displayed as corrupt.

Thanks

Marcus

コメントを表示 · 投稿日時:2024年5月27日 · Marcus Dawideit

0

フォロワー

0

投票

0

コメント


Marcus Dawideitさんがコメントを作成しました:

コメントAttachments and CCs

Hello,

With the example from above and the current attachment token I always get the following error message back:

{
    "error": "RecordInvalid",
    "description": "Record validation errors",
    "details": {
        "base": [
            {
              "description": "Uploads is invalid"
            }
        ]
    }
}

API Request:

{
 "ticket": {
   "comment":  { "body": "See PDF.", "uploads":  ["i2duiFM7GNcgJxo48HJWJFoA1"] }
 }
}

 

Any recommondations or advices ?

 

Thanks !

Best regards,

Marcus

コメントを表示 · 編集日時:2023年4月26日 · Marcus Dawideit

0

フォロワー

0

投票

0

コメント


Marcus Dawideitさんがコメントを作成しました:

コミュニティのコメント Developer - Zendesk APIs

Hi Ken,

In the meantime, have you found a solution ? I´m stucking at the same.

Best regards,

Marcus

 

コメントを表示 · 投稿日時:2023年4月26日 · Marcus Dawideit

0

フォロワー

0

投票

0

コメント