cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to know what we learned at IBC? Check out our learnings on media, remote working and more right here.

Discuss Dropbox Developer & API

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to get a temporary link from file that was uploaded via Dropbox API

How to get a temporary link from file that was uploaded via Dropbox API

Amicao
Explorer | Level 3
Go to solution

Hello, good afternoon for all, i am here again for other problem related to get temporary link from file.

 

I made a Laravel system using the Dropbox API to get a file from user, upload it and later, get a access for this file and delete it if necessary. The problem is that upload the file and Dropbox change the file name to a own Dropbox hash system. And it difficult me to get the temporary link automatically via Laravel, because my system don't know now my file name automatically. Does exist a way to me disable the file name name alteration? Or does exists other way to do this feature more simplest? 

 

I will be gratefull

1 Accepted Solution

Accepted Solutions

Здравко
Legendary | Level 20
Go to solution

@Amicao wrote:

... a file from user, upload it and later, get a access for this file and delete it if necessary. The problem is that upload the file and Dropbox change the file name to a own Dropbox hash system. ...


Hi @Amicao,

It's good idea to you share some piece of your algorithm able to reproduce the issue. Generally Dropbox API doesn't change file name if there is no other file already existing with the same name on the same place (path). Even when such file exist it can be updated, depending on your intention, upload can fails, or automatically rename it (whatever appropriate).

 


@Amicao wrote:

... And it difficult me to get the temporary link automatically via Laravel, because my system don't know now my file name automatically. ...


On successful file upload (either with changed or intended name) actual name gets as a part of the API access point result (take a look on /2/files/upload Returns section, for example). So you (your system) definitely know how your file gets named and the file id too. Using this you can pass it to the 2/files/get_temporary_link call.

 


@Amicao wrote:

... Does exist a way to me disable the file name name alteration? ...


Take a look on "mode" parameter for possible alternatives.

View solution in original post

5 Replies 5

Здравко
Legendary | Level 20
Go to solution

@Amicao wrote:

... a file from user, upload it and later, get a access for this file and delete it if necessary. The problem is that upload the file and Dropbox change the file name to a own Dropbox hash system. ...


Hi @Amicao,

It's good idea to you share some piece of your algorithm able to reproduce the issue. Generally Dropbox API doesn't change file name if there is no other file already existing with the same name on the same place (path). Even when such file exist it can be updated, depending on your intention, upload can fails, or automatically rename it (whatever appropriate).

 


@Amicao wrote:

... And it difficult me to get the temporary link automatically via Laravel, because my system don't know now my file name automatically. ...


On successful file upload (either with changed or intended name) actual name gets as a part of the API access point result (take a look on /2/files/upload Returns section, for example). So you (your system) definitely know how your file gets named and the file id too. Using this you can pass it to the 2/files/get_temporary_link call.

 


@Amicao wrote:

... Does exist a way to me disable the file name name alteration? ...


Take a look on "mode" parameter for possible alternatives.

Amicao
Explorer | Level 3
Go to solution

I discovered the problem, the Laravel Framework libraries doesn't support more the Dropbox API, because Dropbox had modified your API politics, as well as your upload API and others, so my framework is doing a wrong request to save data passing the filename as filepath parameter and not filename parameter, what is resulting in empty filename, then Dropbox is generating a random name with your hash algorithm.

 

But now, i would like to know how I make a upload request without passing the filepath as parameter, but yes the file or binary object from file in Curl request. Because in a framework server side in server-client system, its not capable to get the filepath once this is from client and not from server, and the application sever doesnt allow to upload file in your container temporally, because i am trying to use the Dropbox API.

Здравко
Legendary | Level 20
Go to solution

Hi @Amicao,

I'm glad that my previous post helped you to some extent.

About API changes: If you don't take in mind API state very log ago, API calls (most of them, including upload/download, you are interested in) are not changed or not significantly, at least. The only non back compatible change, recently released (started 2-3 years ago) is drop of long time access token (new can't be issued, despite existing can be used still) and replacement with refresh token for long term use. Everything else is back compatible, at least, if not the same.


@Amicao wrote:

I discovered the problem, the Laravel Framework libraries doesn't support more the Dropbox API, because Dropbox had modified your API politics, as well as your upload API and others, so my framework is doing a wrong request to save data passing the filename as filepath parameter and not filename parameter, what is resulting in empty filename, then Dropbox is generating a random name with your hash algorithm.

...


I have no any idea what you mean here. 🤔 Do you take in mind some time before roughly 5-10 years ago, or even more? If the provider isn't updated the product (tool you are using) so long, ask there. 🤷

 


@Amicao wrote:

...

But now, i would like to know how I make a upload request without passing the filepath as parameter, but yes the file or binary object from file in Curl request. Because in a framework server side in server-client system, its not capable to get the filepath once this is from client and not from server, and the application sever doesnt allow to upload file in your container temporally, because i am trying to use the Dropbox API.


You can NOT save any file in Dropbox user space without name! No chance. You must save uploaded content under some name (whatever is it) at the end, at least. Whenever you get a file (either from the server space or in some user upload session), a file name should be ensured and is usually available in one or other way. To be honest, I can't even imagine a situation that client-server system can't ensure available file name. Probably you have done something wrong there. Fix it, if really need. If I have to bet, this name is available already somewhere, just find its exact place out.

About "temporally" upload space: You can use upload session (/2/files/upload_session/start), where the name/path isn't need at session start and when continue upload in the same session (/2/files/upload_session/append_v2) if need. In such a way you can delay set the name, but can NOT avoid it! At finalization (/2/files/upload_session/finish), you have to pass the place (name and path) where this file have to reside in at the end. That's it.

As a workaround you can use some stable and predictable algorithm (in dependence what are objectives) to set a temporary name, if so much needed (I don't believe it is).

Good luck.

 

ADD: Actually using PHP curl calls you can do whatever you want (even more than the officially supported SDKs can) to large extent! 😉

Amicao
Explorer | Level 3
Go to solution

@Здравко I think you didn't understand. First I wanted to say that the Laravel Framework uses a structure called Filesystem, from which they create "drivers" disks that supposedly said by the community, would support Dropbox, with standardized methods of insertion, deletion etc, however, what I see is that in these methods, it treats the input that would supposedly be the concatenation of the file path with the file name, differentiating when making the request in the lower layer of the framework what the folder path will be and what the file name will be in the Dropbox, which doesn't happen, at least according to community reports, in saying that it used to work, now it doesn't.

So, that's why I'll work with Curl on the top layer of the Framework, giving up the framework's own drivers.

Another question of mine that I don't know if it was clear to you, is that the application must receive a file via POST request from the user, and on the server it must get this binary object from the file via $_FILE and then submit it somehow via Curl request for the Dropbox API.

And from what I saw in the Dropbox documentation, in the "upload" tab it asks for the file path as the body of the request, which would supposedly be the file on the user's machine, but the curl command would have to run on the user's machine too, and not the case here. In this case I will only have the file object and not its path, so how do I instead pass the file path to the command to search and get the binary object, I already pass the binary object?

Здравко
Legendary | Level 20
Go to solution

@Amicao, 🙂 Your questions are outside Dropbox API scope itself. As far as I can see you are confused by usage of your tools. CURL in PHP typically adds file content independent from headers and you can take a look on some tutorial for this. The command line version really by default catches files. Even in this case you can pass a special file - the standard input. Just as example, try following:

echo -n "Hello World" | curl -X POST https://content.dropboxapi.com/2/files/upload \
  -H 'Authorization: Bearer <your access token here>' \
  -H 'Content-Type: application/octet-stream' \
  -H 'Dropbox-API-Arg: {"path":"/upload_test.txt"}' --data-bin @-

What gets up? 😉

To the other things, you should know best what where is. Only you know what is/are field(s) name(s) in use on the site. Just do it!

 

By the way, If you don't know, you can prototype and test API code/algorithms here.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Здравко Legendary | Level 20
  • User avatar
    Amicao Explorer | Level 3
What do Dropbox user levels mean?