Forum Discussion

sajadjaward1's avatar
sajadjaward1
Explorer | Level 4
6 years ago
Solved

Batch copy within Dropbox gives an error

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

  • Greg-DB's avatar
    Greg-DB
    6 years ago

    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.

3 Replies

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    6 years ago

    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's avatar
    sajadjaward1
    Explorer | Level 4
    6 years ago

    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's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    6 years ago

    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.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!