3

What is working right now is i can upload to the root folder of a library using the code below :

 myDropzone.options.url = `${_context.pageContext.web.absoluteUrl}/_api/web/Lists/getById('${_parent.props.listName}')/rootfolder/files/add(overwrite=true,url='${file.name}')`;   

What i want is to be able to send the files to a specific folder. i have tried using the below code but i get 404 error.

 myDropzone.options.url = `${_context.pageContext.web.absoluteUrl}/_api/web/Lists/getById('${_parent.props.listName}')/folders/folder1/files/add(overwrite=true,url='${file.name}')`;   




myDropzone.options.url = `${_context.pageContext.web.absoluteUrl}/_api/web/Lists/getById('${_parent.props.listName}')/rootfolder/folders/folder1/files/add(overwrite=true,url='${file.name}')`;   
0

2 Answers 2

4

I tested below endpoint in fiddler, it works fine.

Correct your endpoint as folders('folder1').

/sites/Developer/_api/web/lists/getByTitle('MyDoc4')/RootFolder/folders('SubFolder')/files/add(url='test.txt',overwrite=true)
7
  • am still getting the error 400 ${_context.pageContext.web.absoluteUrl}/_api/web/Lists/getById('${_parent.props.listName}')/rootfolder/folders('folder1')files/add(overwrite=true,url='${file.name}'); Commented Dec 13, 2018 at 7:59
  • i missed a '/' before files. it works Commented Dec 13, 2018 at 8:03
  • but if i have something like this folders('folder1/folder2'), it doesn't work Commented Dec 13, 2018 at 8:06
  • 1
    Use /_api/web/lists/getByTitle('MyDoc4')/RootFolder/folders('SubFolder')/folders('F')/files/add()
    – Lee
    Commented Dec 13, 2018 at 8:42
  • i am getting the path dynamically,is there any other solution where i can just inject "folder1/subfolder2/subfolder3/..." . The code above is a static way if you know the exact subfolder numbers Commented Dec 13, 2018 at 10:19
1

I will suggest to use GetFolderByServerRelativeUrl() like this

https://<site url>/_api/web/GetFolderByServerRelativeUrl('Documents/test folder1/folder inside test folder/folder3')/files/add(url='test.txt',overwrite=true)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.