<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Java api : How to get already-created download link for a file? in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-api-How-to-get-already-created-download-link-for-a-file/m-p/547339#M26083</link>
    <description>&lt;P&gt;1. To retrieve existing links, you can use &lt;A href="https://dropbox.github.io/dropbox-sdk-java/api-docs/v4.0.1/com/dropbox/core/v2/sharing/DbxUserSharingRequests.html#listSharedLinks--" target="_self"&gt;listSharedLinks&lt;/A&gt; or &lt;A href="https://dropbox.github.io/dropbox-sdk-java/api-docs/v4.0.1/com/dropbox/core/v2/sharing/DbxUserSharingRequests.html#listSharedLinksBuilder--" target="_self"&gt;listSharedLinksBuilder&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. You can modify shared links for different behaviors, such as direct file content access, using &lt;A href="https://help.dropbox.com/files-folders/share/force-download" target="_self"&gt;the URL parameters documented here&lt;/A&gt;.&lt;/P&gt;</description>
    <pubDate>Mon, 27 Sep 2021 17:07:37 GMT</pubDate>
    <dc:creator>Greg-DB</dc:creator>
    <dc:date>2021-09-27T17:07:37Z</dc:date>
    <item>
      <title>Java api : How to get already-created download link for a file?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-api-How-to-get-already-created-download-link-for-a-file/m-p/547158#M26077</link>
      <description>&lt;LI-CODE lang="java"&gt;	public String uploadFile(List&amp;lt;File&amp;gt; list, String dropboxPath) throws Exception {
		
		StringBuilder sb = new StringBuilder("");
		
		for (File f : list) {
			try (FileInputStream in = new FileInputStream(f)) {

				UploadProgress prog = new UploadProgress(f);
				FileMetadata metadata = client.files().uploadBuilder(dropboxPath + f.getName()).withMode(WriteMode.ADD)
						.withClientModified(new Date(f.lastModified()))
						.uploadAndFinish(in, prog);
				System.out.println();
				System.out.println(f.getName() + "matadata : " + metadata.toStringMultiline());
				prog.done();
				
				sb.append(client.sharing().createSharedLinkWithSettings(dropboxPath + f.getName()).getUrl());
				sb.append(System.lineSeparator());
			
			} catch (Exception ex) {
				System.out.println();
				System.out.println("Failed to upload file \"" + f.getName() + "\": " + ex.getMessage());
				System.out.println();
				throw ex;
			}
		}
		
		return sb.toString();
	}
	&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've made a method that uploads files and retrieve download links of them.&lt;/P&gt;&lt;P&gt;my question is :&lt;/P&gt;&lt;P&gt;1. I sometimes got this Exception message :&lt;/P&gt;&lt;P&gt;Exception in thread "main" com.dropbox.core.v2.sharing.CreateSharedLinkWithSettingsErrorException: Exception in 2/sharing/create_shared_link_with_settings: {".tag":"shared_link_already_exists","shared_link_already_exists": ... and so on&lt;/P&gt;&lt;P&gt;probably because I used&amp;nbsp;createSharedLinkWithSettings method multiple times testing.&lt;/P&gt;&lt;P&gt;So. How can I grab Existing download link without trying to recreate them?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. When I click one of the created link to a pdf file, I got a viewer, not a download page.&lt;/P&gt;&lt;P&gt;Is there any way to get a link that gives me a direct download page?&lt;/P&gt;</description>
      <pubDate>Mon, 27 Sep 2021 00:42:31 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-api-How-to-get-already-created-download-link-for-a-file/m-p/547158#M26077</guid>
      <dc:creator>awideksy</dc:creator>
      <dc:date>2021-09-27T00:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: Java api : How to get already-created download link for a file?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-api-How-to-get-already-created-download-link-for-a-file/m-p/547339#M26083</link>
      <description>&lt;P&gt;1. To retrieve existing links, you can use &lt;A href="https://dropbox.github.io/dropbox-sdk-java/api-docs/v4.0.1/com/dropbox/core/v2/sharing/DbxUserSharingRequests.html#listSharedLinks--" target="_self"&gt;listSharedLinks&lt;/A&gt; or &lt;A href="https://dropbox.github.io/dropbox-sdk-java/api-docs/v4.0.1/com/dropbox/core/v2/sharing/DbxUserSharingRequests.html#listSharedLinksBuilder--" target="_self"&gt;listSharedLinksBuilder&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. You can modify shared links for different behaviors, such as direct file content access, using &lt;A href="https://help.dropbox.com/files-folders/share/force-download" target="_self"&gt;the URL parameters documented here&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Sep 2021 17:07:37 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-api-How-to-get-already-created-download-link-for-a-file/m-p/547339#M26083</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2021-09-27T17:07:37Z</dc:date>
    </item>
    <item>
      <title>Re: Java api : How to get already-created download link for a file?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-api-How-to-get-already-created-download-link-for-a-file/m-p/548223#M26102</link>
      <description>&lt;P&gt;Thanks for your answer. I'll post my fixed code for those who might have similar problem with mine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;	public String uploadFileAndGetLink(List&amp;lt;File&amp;gt; list, String dropboxPath) throws Exception {
		
		System.out.println();
		System.out.println("Getting download links...");
		StringBuilder sb = new StringBuilder("");
		
		for (File f : list) {
				
			String link;
			try {
				
				if(!isLinkExists(dropboxPath + f.getName())) {
					System.out.println("Uploading " + f.getName() + "...");
					uploadFile(f, dropboxPath);
					link = client.sharing().createSharedLinkWithSettings(dropboxPath + f.getName()).getUrl();
				} else {
					System.out.println(f.getName() + " is already uploaded, retrieving link...");
					link = client.sharing().listSharedLinksBuilder().withPath(dropboxPath + f.getName()).start().getLinks().get(0).getUrl();
				}
				
				sb.append(link.contains("dl=0") ? link.replace("dl=0", "dl=1") : (link.contains("?") ? link + "&amp;amp;dl=1" : link + "?dl=1"));
				sb.append(System.lineSeparator());
			
			} catch (Exception ex) {
				
				System.out.println();
				System.out.println("Failed to upload file \"" + f.getName() + "\": " + ex.getMessage());
				System.out.println("Try deleting uploaded files...");
				System.out.println();
				
				for (int i = 0; i &amp;lt; list.indexOf(f); i++) {
					
					deleteLink(dropboxPath + list.get(i).getName());

				}
				
				throw ex;
				
			}
		}
		
		System.out.println();
		return sb.toString();
	}
	
	private void uploadFile(File f, String path) throws Exception {

		FileInputStream in = new FileInputStream(f);

		UploadProgress prog = new UploadProgress(f);
		FileMetadata metadata = client.files().uploadBuilder(path + f.getName()).withMode(WriteMode.ADD)
				.withClientModified(new Date(f.lastModified())).uploadAndFinish(in, prog);
		System.out.println();
		System.out.println(f.getName() + "matadata : " + metadata.toStringMultiline());
		prog.done();

		in.close();

	}
	
	private boolean isLinkExists(String path) {
		
		boolean result = true;
		
        try {
            client.files().getMetadata(path);
        } catch (Exception e){
        	result = false;
        }

        return result;
		
	}
	
	private void deleteLink(String path) {
		
		try {
			
			if(isLinkExists(path)) client.files().deleteV2(path);
			
		} catch (Exception e) {
			System.out.println();
			System.out.println("Failed to delete uploaded file \"" + path + "\"");
			e.printStackTrace();
			System.out.println();
		}
		
	}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Oct 2021 02:31:47 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-api-How-to-get-already-created-download-link-for-a-file/m-p/548223#M26102</guid>
      <dc:creator>awideksy</dc:creator>
      <dc:date>2021-10-01T02:31:47Z</dc:date>
    </item>
    <item>
      <title>Re: Java api : How to get create direct download link for a file?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-api-How-to-get-already-created-download-link-for-a-file/m-p/624864#M28908</link>
      <description>&lt;P data-unlink="true"&gt;hi i want to know how to create direct download link for ab website file hosted in dropbox&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 13:01:43 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-api-How-to-get-already-created-download-link-for-a-file/m-p/624864#M28908</guid>
      <dc:creator>himalayantrekkers10</dc:creator>
      <dc:date>2022-09-26T13:01:43Z</dc:date>
    </item>
    <item>
      <title>Re: Java api : How to get create direct download link for a file?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-api-How-to-get-already-created-download-link-for-a-file/m-p/624881#M28911</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1577038"&gt;@himalayantrekkers10&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;hi i want to know how to create direct download link for ab &lt;A href="https://himalayantrekkers.com/" target="_self"&gt;website&lt;/A&gt; file hosted in dropbox&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Hi &lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1577038"&gt;@himalayantrekkers10&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;At the beginning can you clarify what's not clear in Greg's post above? There are directions you can use.&lt;/P&gt;&lt;P&gt;In addition you don't need to check if a link exists or not (in such a way you can speed up you application - less calls). If 'createSharedLinkWithSettings' fails because of already existing link, the error (exception) contains this link. You have to just catch it. &lt;img class="lia-deferred-image lia-image-emoji" src="https://www.dropboxforum.com/html/@41457EF40051AFF130FDBFE21B496926/emoticons/1f609.png" alt=":winking_face:" title=":winking_face:" /&gt; Much faster!&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Sep 2022 12:21:28 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-api-How-to-get-already-created-download-link-for-a-file/m-p/624881#M28911</guid>
      <dc:creator>Здравко</dc:creator>
      <dc:date>2022-09-25T12:21:28Z</dc:date>
    </item>
  </channel>
</rss>

