microsoftarchive / wunderlist.js

Wunderlist Javascript SDK
https://developer.wunderlist.com/documentation/tools/wunderlist.js
120 stars 29 forks source link

Unable to create a file after upload step. error Upload was not finished properly #21

Closed qadirsuh closed 6 years ago

qadirsuh commented 6 years ago

Hello,

I am trying to create file after uploading step. here is my code

if (data.isValid) {
        const dir = "./telegram_uploads";
        telegramBot.downloadFile(telegramResponse.photo[0].file_id, dir).then(function (response) {

            const fileName = "./" + response;
            const mimeType = mime.getType(fileName);

            console.log("mimeType", mimeType);

            const uploadData = {
                content_type: mimeType,
                file_name: fileName,
                file_size: telegramResponse.photo[0].file_size
            };

            wunderlistAPI.http.uploads.create(uploadData)
                .done(function (createUploadResponse, statusCode) {

                    console.log("createUploadResponse", createUploadResponse, statusCode);

                    var createFileData = {
                        upload_id: createUploadResponse.id,
                        task_id: 3846472873, // hardcoded todo1 task
                        local_created_at: new Date("2013-08-02T11:58:55.123Z")
                    };

                    wunderlistAPI.http.files.create(createFileData)
                        .done(function (createFileResponse) {
                            console.log("createFileResponse", createFileResponse);
                        })
                        .fail(function (err) {
                            console.error('there was a problem create file', err);
                        });
                })
                .fail(function (err) {
                    console.error('there was a problem upload file', err);
                });
        }).catch(function (err) {
            console.log("downloadFile err", err);
        });
    }

I am getting error on create file API.

there was a problem create file { error: 
   { type: 'validation_error',
     translation_key: 'api_error_validation_error',
     message: 'The information you sent could not be processed (validation failure).',
     upload: [ 'Upload was not finished properly' ] } }

Here is the complete log

telegramResponse  { message_id: 5162,
  from: 
   { id: 157895645,
     is_bot: false,
     first_name: 'Qadir',
     username: 'qadirsuh',
     language_code: 'en-US' },
  chat: 
   { id: -269600145,
     title: 'Airhome24 - Gubelstrasse 24, Zug :: airhomeCHLU5',
     type: 'group',
     all_members_are_administrators: true },
  date: 2018-05-18T07:56:59.000Z,
  photo: 
   [ { file_id: 'AgADBAADEKwxG0CW8FMeLo8vosukgIhxiRoABCN6pAHob8lfV44FAAEC',
       file_size: 811,
       file_path: 'photos/file_73.jpg',
       width: 90,
       height: 42 },
     { file_id: 'AgADBAADEKwxG0CW8FMeLo8vosukgIhxiRoABNnJIcD3yGXvWI4FAAEC',
       file_size: 12773,
       width: 320,
       height: 148 },
     { file_id: 'AgADBAADEKwxG0CW8FMeLo8vosukgIhxiRoABDNHnyQirKjXWY4FAAEC',
       file_size: 60406,
       width: 800,
       height: 371 },
     { file_id: 'AgADBAADEKwxG0CW8FMeLo8vosukgIhxiRoABEgqeVZarExHVo4FAAEC',
       file_size: 75957,
       width: 960,
       height: 445 } ] }
mimeType image/jpeg
createUploadResponse { id: 194990275,
  user_id: 83893571,
  state: 'new',
  type: 'upload',
  expires_at: '2018-05-18T08:02:02.402Z',
  part: 
   { url: 'https://upload.wunderlist.io/f8d10eb0-3c9e-0136-bdb1-22000a7d84c2-1526630221-932543?partNumber=1&uploadId=ocTB4usGTKDr5moJdhuGOO4kz.eVC9YPYukhmSYjJFr7r5UZUKUjbfK_8CTtRMRQxvSqvRLAN2Y1N42w39sZfbS9JVPr5c30aT1Rjwjbv7sDjjeOl3g3wpu0iOU7iOuF',
     date: 'Fri, 18 May 2018 08:02:02 UTC +00:00',
     authorization: 'AWS AKIAJEN6W4AO3LJODOAA:QFdXLxECwVDp9TPBSX8TEU10K48=' } } 201
there was a problem create file { error: 
   { type: 'validation_error',
     translation_key: 'api_error_validation_error',
     message: 'The information you sent could not be processed (validation failure).',
     upload: [ 'Upload was not finished properly' ] } }
qadirsuh commented 6 years ago

Any comment on this please.

qadirsuh commented 6 years ago

I have done it myself but not with wunderlist.js I have done it via some CURL commands too.