I can use this code to upload my file to the dropbox through html.
<script>
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
//// files is a FileList of File objects
for (var i = 0, f; f = files[i]; i++) {
$.ajax({
url: 'https://content.dropboxapi.com/2/files/upload',
type: 'post',
data: f,
processData: false,
contentType: 'application/octet-stream',
headers: {
"Authorization": "Bearer <REDACTED>",
"Dropbox-API-Arg": '{"path": "/' + f.name + '","mode": "add"}'
},
success: function (data) {
console.log(data);
},
error: function (data) {
console.log(data);
}
})
}
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>
However, I would like to get the shared link of the uploaded file. I tried this code but couldn't get it.
<script>
function handleSharedLink(evt) {
var path = "TARCpace.apk";
$http.post("https://api.dropboxapi.com/2/sharing/get_shared_links",
JSON.stringify({
"path": path
}),
{
headers: {
'Content-Type': "application/json",
'Authorization': "Bearer <REDACTED>"
}
}
).then(function (data) {
console.log(data);
$('#output').html(result);
})
}
var output = document.getElementById('getlink').addEventListener('click', handleSharedLink, false);
</script>
How can i get the shared link? Is the method correct?