cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more 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: 

Problem with paths using create_shared_link_with_settings

Problem with paths using create_shared_link_with_settings

emarco
Explorer | Level 3
Go to solution

Hey,

I'm trying to make a php code that will automatically create a shared link for the files I'm uploading and add it to an XML file.

Both the upload and XML file are updating correctly, but I'm stuck with the generation of the link. This is the part of code that i'm running right now:

 

	$parameters = array('path' => $filename);

	$headers = array('Authorization: Bearer token','Content-Type: application/json');
	$curlOptions = array(
        CURLOPT_HTTPHEADER => $headers,
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => json_encode($parameters),
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_VERBOSE => true
    );

	$ch = curl_init('https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings');
	curl_setopt_array($ch, $curlOptions);

	$linkdropbox = curl_exec($ch);
	curl_close($ch);
	$nodeDescargaText = $xml -> createTextNode($linkdropbox);

Filename is 

 

	$filename = "/".$_FILES['inputFile']['name'];

So, I keep getting errors like:

"The root path is unsupported"

"Malformed path"

I have tried leaving the root both with "" or with "/",  and also have tried putting in the root the name of the Apps folder, (Apps, Aplicaciones, manualesint), the last one being the folder to where are the files being uploaded. None seems to make this work. I have tried all of them both with a "/" after, before, both, or without.

On the upload code, I'm uploading the file using "/"+name of the file, and it's working like a charm.

 

Any help will be appreciated!

 

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

[Cross-linking for reference: https://stackoverflow.com/questions/53499573/problem-with-paths-using-create-shared-link-with-settin... ]

Getting a shared link for the root is not supported, so supplying a path like "" or "/" is expected to fail like that.

To get the shared link for a file, you should supply the full path to the file, including the file name and extension. For example, for a file "example.xml" in a folder "Documents", the path would be: "/Documents/example.xml".

You can construct these paths manually if you want, but it's better to use the paths returned by the API itself. For instance, when uploading a file, the API returns the metadata for the uploaded file in the response body. Specifically, you should use the returned 'path_lower' value.

View solution in original post

4 Replies 4

Greg-DB
Dropbox Staff
Go to solution

[Cross-linking for reference: https://stackoverflow.com/questions/53499573/problem-with-paths-using-create-shared-link-with-settin... ]

Getting a shared link for the root is not supported, so supplying a path like "" or "/" is expected to fail like that.

To get the shared link for a file, you should supply the full path to the file, including the file name and extension. For example, for a file "example.xml" in a folder "Documents", the path would be: "/Documents/example.xml".

You can construct these paths manually if you want, but it's better to use the paths returned by the API itself. For instance, when uploading a file, the API returns the metadata for the uploaded file in the response body. Specifically, you should use the returned 'path_lower' value.

emarco
Explorer | Level 3
Go to solution

Hey Greg,

Thanks for the input, will give it a try and get back with the results!

emarco
Explorer | Level 3
Go to solution

Okay, so after testing what you told me, I managed to make it "work".

The problem I am having now, is that I append the result into a text node, and when clicking that, I get redirected to something like:

http://192.168.1.101/downloads/%7B%22.tag%22:%20%22file%22,%20%22url%22:%20%22https:/www.dropbox.com...

 

Whilst, obviously, I just want the download link which is in the first line, in this case it being:

https:/www.dropbox.com/s/3qy4rbv5n5nlabcm/example.xml

Have deleted the file since it was an example, but the link was working previously.

Any idea how to just get the link back?

Really appreciating your help Greg

emarco
Explorer | Level 3
Go to solution

Managed to do that with a string filter function! Thanks a lot for your help Greg 🙂

Need more support?
Who's talking

Top contributors to this post

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