cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Re: Uploading multiple files with UploadSession with TypeScript

Uploading multiple files with UploadSession with TypeScript

DavidM27
Explorer | Level 4
Go to solution

Hi,

I'm facing an issue with the UploadSessionFinishBatch method with TypeScript.

I'm having this error :

Error in call to API function \"files/upload_session/finish_batch\": request body: entries: unknown field 'contents

It seems like the "contents" parameter is not supposed to be here and makes the call crash. But in TypeScript the contents is required.

In some example I found on the web I've never seen the contents parameter. Is it a problem of type due to TypeScript SDK ? Or there is something I miss ?

Here is the code I use

const finishUploadBatchArg: DropboxTypes.files.UploadSessionFinishBatchArg = {
      entries: [],
    }

// For each file I do : 
const response = await this.dropBox.filesUploadSessionStart(uploadSessionStartArg)
        sessionId = response.session_id
        const cursor: DropboxTypes.files.UploadSessionCursor = {
          contents: file,
          offset:file.size,
          session_id: sessionId,
        }
        const commitInfo: DropboxTypes.files.CommitInfo = {
          contents: file,
          path: filePath,
          autorename: true,
        }

        const finishSessionArg = {
          contents : file, //This one is unknown from what I understand of the error I get
          cursor: cursor,
          commit: commitInfo,
        }
        finishUploadBatchArg.entries.push(finishSessionArg)
//Then I call the finish batch method : 
const response: DropboxTypes.files.UploadSessionFinishBatchLaunch = await this.dropBox.filesUploadSessionFinishBatch(finishUploadBatchArg)

By the way all the session start goes well.

Can you please help me on this ?

 

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

Thanks for writing this up! This does seem to be a bug in the SDK. The UploadSessionFinishArg type has a 'contents' field because it's how you supply the data if/when calling filesUploadSessionFinish (not the batch version), where it gets set as the request body, but it's not actually needed or expected for filesUploadSessionFinishBatch. I'll ask the team to fix this up.

Similarly, in this case you should just be setting the file data on UploadSessionStartArg itself, not UploadSessionCursor or CommitInfo. Those definitions are also wrong, so I'll ask the team to fix that too.

As a workaround though, it looks like you can do the following after defining each of these:

delete cursor.contents
delete commitInfo.contents
delete finishSessionArg.contents

 

 

View solution in original post

4 Replies 4

Greg-DB
Dropbox Staff
Go to solution

Thanks for writing this up! This does seem to be a bug in the SDK. The UploadSessionFinishArg type has a 'contents' field because it's how you supply the data if/when calling filesUploadSessionFinish (not the batch version), where it gets set as the request body, but it's not actually needed or expected for filesUploadSessionFinishBatch. I'll ask the team to fix this up.

Similarly, in this case you should just be setting the file data on UploadSessionStartArg itself, not UploadSessionCursor or CommitInfo. Those definitions are also wrong, so I'll ask the team to fix that too.

As a workaround though, it looks like you can do the following after defining each of these:

delete cursor.contents
delete commitInfo.contents
delete finishSessionArg.contents

 

 

DavidM27
Explorer | Level 4
Go to solution

Thank you, for your reply it does work as a workaround. Can you please keep me informed when this is fixed ?

 

Greg-DB
Dropbox Staff
Go to solution

Yes, I'll follow up here once I have an update on this. I can't promise when that will be though.

Greg-DB
Dropbox Staff
Go to solution

The team has updated the SDK to no longer set 'contents' as required in the latest JavaScript SDK version, v9.7.0, so you should be able to use this as expected without the workaround now.

Need more support?