Wednesday, October 12, 2011

Dropbox Updates Have Landed

Just wanted to let you guys know that I have made some updates to the Dropbox API Library. These changes are in reaction to the new functionality available in the new Dropbox API. There are a few new methods and I removed the link method. I will outline the changes below.

Here is the Github Repo

I did make some changes to some of the existing methods. The now accept an array of parameters so that you can specify different parameters that can be passed to the API. There were a few new methods that were added, they are as follows:
revisions($path, array $params = array(), $root='dropbox')
restore($path, $revision, $root='dropbox')
search($path, $query, array $params = array(), $root='dropbox')
shares($path, $root='dropbox')
media($path, $root='dropbox')
The revisions method
revisions($path, array $params = array(), $root='dropbox')
Will return an array of revisions for a particular file or the revisions of files in a particular folder.

The restore method
restore($path, $revision, $root='dropbox')
Will roll a particular file back to a previous revision. Specify the revision by using the 'rev' hash that is returned when you make a call to the revisions method.

The search method
search($path, $query, array $params = array(), $root='dropbox')
Will search a particular path in your dropbox folders for any files that match the query.

The shares and media methods have replaced the link method.
shares($path, $root='dropbox')
media($path, $root='dropbox')
Both methods link to a file in dropbox the difference is that media links directly to the file and should be used for things link streaming. Shares creates a new link to a file and is more geared towards publicly displaying your content. Both calls also return an expiration date which indicate when the link will become invalid.

As always if you have any questions or problems post them in the comments but as it stands right now things seem to be pretty stable.

12 comments:

  1. Hi Jim,
    Thanks for what looks like a great library, but I’m loading sparks into PyroCMS, a CMS built onto CI (not that this matters).

    So far, simple sparks have been a doddle and all went well.

    Now I’m using your dropbox spark, I’ve hit a problem as $params need to get passed.

    Your instructions say:

    ...load the library like this:

    $this->load->library('dropbox', $params);
    You can also use this library with Sparks. Simply install using sparks then call.

    $this->load->spark('dropbox/1.0.0');

    If I use

    $this->load->spark('dropbox/1.2.2');

    then of course, I get

    Call to a member function get_request_token() on a non-object ...

    as the $params (which is an array of credential) aren’t getting passed.

    If I try

    $this->load->spark('dropbox/1.2.2', $params);
    Could not autoload object of type ‘key’ (xxxx
    ...

    because it seems you can’t pass $params like that.

    Been through the spark docs too, and unless I’m missing something, I don’t see how I’d do this. Any suggestions? Thanks!

    ReplyDelete
    Replies
    1. Hmm yes it appears that sparks has altered their loader. The second parameter in the load sparks call is now used to autoload additional resources not pass parameters. I will have to investigate this further. In the mean time you can move the library files into the appropriate places then load it as you would a standard CI library.

      Delete
  2. Great library that I almost have up and running in my app.

    I am running into an issue when I try upload a file into Dropbox.

    For the $filepath param, I'm passing in $_FILES["userfile"]["temp_name"] from the form where the user selected the file. It works but it uploads the file with the wacky tmp file name.

    $_FILES["file"]["name"] doesn't work, since it really doesn't point to the file on the server, but it's got the name I want.

    How do I upload and get the filename I expect?

    Thanks!

    ReplyDelete
    Replies
    1. sorry, $_FILES["userfile"]["temp_name"] should be: $_FILES["userfile"]["tmp_name"] !

      I CAN get it to work with a few extra steps:

      >>>
      $dbobj = $this->dropbox->add('/'.$folder_name, $_FILES["userfile"]["tmp_name"], $params, 'sandbox');
      $tmp_name = substr($_FILES["userfile"]["tmp_name"],4);
      $dbobj = $this->dropbox->copy('/'.$folder_name.'/'.$tmp_name, '/'.$folder_name.'/'.$_FILES["userfile"]["name"], 'sandbox');
      $dbobj = $this->dropbox->delete('/'.$folder_name.'/'.$tmp_name, 'sandbox');
      <<<

      I'm just thinking that I'm missing something obvious here.

      Thanks for any wisdom you can share!

      -Paul

      Delete
    2. Hi Paul,

      Unfortunately the way the library is designed (and partly the way Dropboxes API works) the file name used is whatever it's named on your server. So since you are using tmp_name which is created by PHP you will get unpredictable file names.

      There are a few ways around this:

      First you could just rename the file on your server prior to adding it to dropbox. This is probably the better option simply because it will reduce the number of calls you make to the dropbox API.

      Second you could essentially do what you are already doing and alter the file name after it's added to dropbox. If you go this route I would recommend you use the 'move' method instead of a copy and delete. It accomplishes the rename with a single call instead of two.

      Delete
  3. Hello how I download a file from my dropbox?

    ReplyDelete
  4. Thank you for these photos, I really liked them.

    ReplyDelete
  5. Very useful information for people, I think this is what everyone needs.

    ReplyDelete
  6. Every time students experience challenges with their home tasks, they start thinking about some smart solutions to solve this issue. Some students google “Who can do my homework for me?”, others search homework help on freelance platforms. Both methods can be useful, but they also are risky and do not guarantee 100% quality paper, on-time delivery, or free revisions. However, there is one more way to cope with an assignment, but unlike the previous two, it excludes all the risks mentioned above. You can receive professional writing help on homeworkfor.me.

    ReplyDelete
  7. hietkenhadepmoi.vn - công ty thiết kế nhà đẹp uy tín. Thiết kế nhà - thiết kế nhà đẹp mới - thiết kế thi công nhà đẹp - thiết kế xây dựng nhà đẹp - mẫu nhà đẹp mới. Tổng hợp các mẫu nhà mái thái đẹp - mẫu nhà phố đẹp - mẫu biệt thự đẹp sang trọng.
    Liên hệ ngay với công ty Thiết kế nhà đẹp mới để được tư vấn và báo giá miễn phí!

    Từ khóa thiết kế nhà đẹp mới :
    #thietkenhadepmoi #thietkenhadepmoivn #thietkennha #thietkennhadep #maunhadepmoi #thietkennhadepmoi #thietkennhauytin #maubietthudep #maunhamaithaidep #mauthietkenhadep #thietkexaydungnhadep #maunhaphodep #congtythietkenhadep #thietkethicongnhadep #thietkexaydungnhadep #maunhadepmoi #maunhamoi #xaydungnhadep #congtynhadep

    https://www.flickr.com/people/188536077@N07/
    https://trello.com/thietkenhadepmoivn
    http://www.folkd.com/user/Thiekenhadepmoivn
    https://www.diigo.com/profile/thietkenha1
    https://www.instapaper.com/p/Thiekenhamoivn

    Website: Thietkenhadepmoi.vn

    ReplyDelete
  8. Wesite https://soicau247.me được biết đến là một diễn đàn được thành lập dành riêng cho “tín đồ” xổ số . Đặc biệt, để hỗ trợ người chơi tìm được những con số may mắn, tỷ lệ trúng cao nên Soi Cầu 247 đã áp dụng các phương pháp soi cầu lô hiện đại
    Số 16 Liễu Giai, Ba Đình, Hà Nội
    sdt: 0989898989

    #soicau247me #soicau247 #soicaume247 #chuyengiasoicau247

    https://www.facebook.com/soicau247me
    https://www.plurk.com/soicau247me
    https://twitter.com/soicau247me
    http://www.folkd.com/user/soicau247me
    https://mix.com/soicau247me
    https://gab.com/soicau247me
    https://trello.com/soicau247me
    https://vn.linkedin.com/in/soicau247me
    https://oneway.com/soicau247me

    ReplyDelete
  9. PetAddict.net - The best place where you can find everything about your pet!Name: Pet Addict \r\n Email: petaddict.net@gmail.com \r\n https://petaddict.doodlekit.com/home# \r\n https://www.stem.org.uk/users/petaddict \r\n Hastag: #PetAddict, #PetAddictnet, #DogPetAddict, #CatPetAddict, #RabbitPetAddict, #FishPetAddict, #BirdPetAddict, #ReptilePetAddict, #SmallPetPetAddict, #OtherPetPetAddict, /m/068hy, /m/0bt9lr, /m/01yrx, /m/06mf6, /m/0ch_cf, /m/015p6, /m/06bt6, /m/06dmvr, /m/0jbk

    ReplyDelete