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: 

Batch copy within Dropbox gives an error

Batch copy within Dropbox gives an error

sajadjaward1
Explorer | Level 4
Go to solution

Hello All!

 

I am using Dropbox Javascript SDK to manage my files within Dropbox. I have come across a scenario where I need to copy 1 or many files (depends) into a single folder.

 

For this, I am using the filesCopyV2 api and proving different paths as the source, but the destination would be the same. Here's the sample code which I have tried in Node JS.

const randomNum = makeRandomId(10);
const filePaths = [];

        files.forEach(file => filePaths.push({ from_path: '/Source/' + file, to_path: '/Destination/' + randomNum }));
        const result = await dbx.filesCopyBatchV2({ entries: filePaths, autorename: false });
        console.log(result);

Now when I execute this piece of code, it works fine for the first file only. Starting from the next file, I am getting a relocation error. The response is shown below:

{
    ".tag": "complete",
    "entries": [
        {
            ".tag": "success",
            "success": {
                ".tag": "folder",
                "name": "KQMcvsrofA",
                "path_lower": "/destination/kqmcvsrofa",
                "path_display": "/Destination/KQMcvsrofA",
                "id": "id:BhIiassdeAAALg"
            }
        },
        {
            ".tag": "failure",
            "failure": {
                ".tag": "relocation_error",
                "relocation_error": {
                    ".tag": "to",
                    "to": {
                        ".tag": "conflict",
                        "conflict": {
                            ".tag": "folder"
                        }
                    }
                }
            }
        }
    ]
}

For instance, if I were to copy 2 files, the first file is copied and the second file is not. 

 

How can I solve this issue? I hope I am using the correct API provided by official Dropbox Team but please correct me if I am wrong.

 

Thank you

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

Yes, you can use this filesCopyBatchV2 method to copy files from multiple different locations into one folder. When doing so though, each 'to_path' shouldn't all be exactly the same. The 'to_path's can all be inside the same folder, but they should include the different file names so they don't conflict with each other.

View solution in original post

3 Replies 3

Greg-DB
Dropbox Staff
Go to solution

This 'failure/relocation_error/to/conflict/folder' error indicates that the operation failed because there is already a folder at the destination path you specified. 

 

Note that when specifying a destination path like this, you should specify the full path where you want to put the item, including both the path of the parent folder, as well as the desired name of the file/folder itself. 

 

In your code, you're setting the destination as `'/Destination/' + randomNum ` for each `file`, and you mentioned "the destination would be the same", so it sounds like this error is to be expected. You will need to set a distinct `to_path` for each item. For example, perhaps you want to do something like:

to_path: '/Destination/' + randomNum + '/' + file

sajadjaward1
Explorer | Level 4
Go to solution

Thank you for replying.

 

Is there any way that I can copy all the files from different paths into a same destination folder? I do not want to end up having so many folders created at the destination for each file that I am copying.

 

Does Dropbox have an API which supports this method?

 

Thank you again

Greg-DB
Dropbox Staff
Go to solution

Yes, you can use this filesCopyBatchV2 method to copy files from multiple different locations into one folder. When doing so though, each 'to_path' shouldn't all be exactly the same. The 'to_path's can all be inside the same folder, but they should include the different file names so they don't conflict with each other.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    sajadjaward1 Explorer | Level 4
What do Dropbox user levels mean?