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: 

Re: file sharing app

file sharing app

Mark S.115
New member | Level 1

I'm using Dropbox to back up files for my app. I want to enable users to share files that are stored on Dropbox. Currently the app gets a share link and reformats it in a way that when clicked, the app will open and then a post request will attempt to get the file from the share link. So far, instead of getting the file I get a web page.

From inside the app I'm using a post request with the share link followed by ?dl=1. Any advice? Is there a better way to do this? Like I said, it's not working.

9 Replies 9

Dave C.5
Helpful | Level 7

Of the top of my head, the front end of the link changes as well. Create one and go to the page, and check what the link on the download button is, that has the ?dl=1 at the end, but i think they adjust the front as well, (i dont have one here to look at sorry)

Mark S.115
New member | Level 1

Thanks for the answer, I looked into it and it appears that it goes to something like... https://dl.dropboxusercontent.com/content_link/ ... and then a string that doesn't look anything like the short string in the original link.

I'm guessing this means it isn't going to work.

I'm exploring the possibility of using copy_ref, and send the copy_ref as a parameter to the app when it opens... then have it automate adding the file to the owners dropbox and then downloading the file. It's a little clunky if the person receiving the file hasn't already authorized Dropbox in the app, but it should work and that may be what I have to do.

Steve M.
Dropbox Staff

Using ?dl=1 should indeed cause the file to get downloaded (after a redirect). What's the issue you're running into?

Mark S.115
New member | Level 1

I am trying to do it automatically and without having the phone open a browser. I don't really want the file saved to disk, I just want the file contents. Ideally the user gets an email that says, "Bob shared a file with you from this great app!" The person clicks the link and the app opens, downloads the file from Dropbox and opens the file.

I use the API to get a short link, I pass the short link into my app, attach the "?dl=1" to the link and use a post request to try to retrieve the data. What is returned is a bunch of what appears to be html. I admit that I'm no expert in using POST. Any thoughts on what I might be doing wrong?

Steve M.
Dropbox Staff

You shouldn't be using a POST... just a GET.

You might want to use ?raw=1 instead of ?dl=1, but they're similar. The response should be a redirect. Depending on what method/library you're using to fetch the URL, it may follow the redirect automatically.

If it doesn't, you can do it yourself. You'll get a 302 response with a Location header. The Location header will contain a URL, and you can fetch the content at that URL.

Greg-DB
Dropbox Staff

For reference, the parameters for shared links are documented here:

https://www.dropbox.com/help/201

Mark S.115
New member | Level 1

When I do the request, instead of getting the file data I get this:

<html>
 <head><title>Found</title></head>
 <body>
   <h1>Found</h1>
   <p>The resource was found at <a href="https://dl.dropboxusercontent.com/content_link/blahblahblah?dl=1">https://dl.dropboxusercontent.com/content_link/blahblahblah?dl=1</a>;
you should be redirected automatically.

<!--  --></p>
   <hr noshade>
   <div align="right">WSGI Server</div>
 </body>
</html>

I'm going to try parsing this response and pulling out the link and running the GET again. It just seems that this would be a common enough task that it would be more straight forward than that.

For the record, I read the documentation which is why I know to use ?dl=1. I also tried ?raw=1, and I tried adding them both. None of these give me the file.

If this sheds some light on the problem, I am using network.request from Corona SDK. Supposedly this handles redirects. Also, I have tried using short_url = true and short_url = false. I found out that it needs to be "false" because the short_url provided by your system includes ?dl=0.

Steve M.
Dropbox Staff

That's the redirect I mentioned. I would strongly recommend looking at the Location header rather than trying to parse the returned HTML. The header should contain the same URL but not require any fragile parsing.

I don't have any direct experience with Corona SDK, but I'd agree that the network.request documentation makes it look like the default behavior is to follow redirects. I don't have any insight as to why that isn't working as expected.

Since it looks like you're getting the original response (before the redirect), I'd suggest using event.responseHeaders.Location to get the URL from the 302 response. Or ping the Corona folks to figure out why the automatic redirect following isn't working.

Mark S.115
New member | Level 1

Thank you, that got it done. For whatever reason the error was not being handled. I turned off their error handling (in case they ever changed it) and made my own error handling function as you directed and now it works.

I have a character sheet app for role playing games and I want to enable people to make a character sheet for someone else and email it to them. Thanks to your advice it now works by sharing a file saved on Dropbox. If you are interested in the app you can check it out at https://www.legendofus.net. The feature should be live in a couple of weeks. Hopefully people will like it.

Need more support?