When picking files from the dropbox (V2), I am trying to get the shared link url using this below code.
internal inner class GetDropboxSharableURLTask(file_path: String, pathLower: String) : AsyncTask<String, Void, Void>() {
private var pDialog: ProgressDialog? = null
private var dropbox_url: String? = file_path
private var db_pathLower: String? = pathLower
override fun onPreExecute() {
super.onPreExecute()
pDialog = ProgressDialog(context)
pDialog!!.setCancelable(false)
pDialog!!.setMessage(context?.resources?.getString(R.string.please_wait))
pDialog!!.show()
}
override fun doInBackground(vararg urls: String): Void? {
try {
val shareLink = DropboxClientFactory.getClient().sharing().getSharedLinkMetadata(db_pathLower)
dropbox_url = getShareURL(shareLink.url)!!.replaceFirst("https://www".toRegex(), "https://dl")
return null
} catch (e: Exception) {
e.printStackTrace()
return null
}
}
fun getShareURL(strURL: String?): String? {
var conn: URLConnection? = null
var redirectedUrl: String? = null
try {
val inputURL = URL(strURL)
conn = inputURL.openConnection()
conn!!.connect()
val `is` = conn.getInputStream()
println("Redirected URL: " + conn.url)
redirectedUrl = conn.url.toString()
`is`.close()
} catch (e: MalformedURLException) {
Log.d("", "Please input a valid URL")
} catch (ioe: IOException) {
Log.d("", "Can not connect to the URL")
}
return redirectedUrl
}
override fun onPostExecute(feed: Void?) {
// TODO: check this.exception
// TODO: do something with the feed
pDialog!!.hide()
Log.d("url", dropbox_url)
val intent = Intent()
intent.putExtra(Constant.KEY_DROPBOX_PICKER, dropbox_url)
context?.setResult(Activity.RESULT_OK, intent)
context?.finish()
}
}
I am getting the error as below -
com.dropbox.core.v2.sharing.SharedLinkErrorException: Exception in 2/sharing/get_shared_link_metadata: SHARED_LINK_NOT_FOUND
This above error is thrown when calling getSharedLinkMetadata(db_pathLower)
Though, earlier, I was using the similar code in dropbox V1
, but as soon as I switched to newer version of the dropbox API, i.e, dropbox V2
, I started getting this error when trying to get the actual sharing url of dropbox, (the one which must contain the file extension as well).
The expected url should be like this - https://dl.dropbox.com/s/hpe1gjfb4aqsv3e/property_1523965639_img.jpeg?dl=0
but, what I am getting is something like https://dl.dropboxusercontent.com/apitl/1/AAD62_lYN5n_cYyRQWhg_rmXGJPFzqF5m8OJpNt_SIIxG7bVvmO6X5d1pKg7uulM1vEBWx_X9PZ9i3vFy-jb3eBC-M_q3YCWRmPrdAwpQ7kqSFGCIPrZaHNC44YRjwXGXYTbnqMO1hPhKb-G5matDzTABUQOssB-LIN4qWoJmPnuhNgzpL9FO4ibet4uBPoef_SLZLjupsOV9PKYUhtPxY_NY7HjymZSHsQh67m4HoBN4YgEAPot0KMAsV1eE3WCjK0XbD1YfGqdsVI9H40KUQ_9R-nmAouoqdbA37G5CXjQKYPC8cENTvN2pjHKwCnHvgI
just because of that error.
Please, let me the know the thing, which I need to modify in order to get the dropbox sharing url (along with file extension), and to avoid the above error, as soon as the file is selected / clicked.