This project is read-only.

Return absolute file URL(s)

Apr 25, 2011 at 12:33 AM

Is there any sample code or documentation demonstrating how to retrieve an absolute file URL for a file or files in a directory and maintain authentication? I have tried to accomplish this with the following code but a series of oauth variables with the same values are appended to the end of the returned URLs resulting in the nonce variable giving an error when clicking one URL to the next. (https://api-content.dropbox.com/0/files/dropbox/Public/Songs/01%20Bang.mp3?oauth_consumer_key=tph4c68u7fdveor&oauth_nonce=6512554&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1303686904&oauth_token=3xvibo8s1slu3jm&oauth_version=1.0&oauth_signature=sIEdvKddmInVUs6EnuvfWKFGIxY=

    public DataTable getURLs(String directory)
    {
        DataTable dtFiles = new DataTable();
        dtFiles.Columns.Add("File");
        dtFiles.Columns.Add("URL");

        try
        {
            ICloudDirectoryEntry folder = storage.GetFolder(directory);
      
            foreach (ICloudFileSystemEntry fsentry in folder)
            {
                if (fsentry is ICloudFileSystemEntry)
                {
                    dtFiles.Rows.Add(fsentry.Name, storage.GetFileSystemObjectUrl(fsentry.Name, fsentry.Parent));
                }
            }
        

        // close the cloud storage connection
        if (storage.IsOpened)
        {
            storage.Close();
        }
        }
        catch (Exception e)
        {
        }
        return dtFiles;
    }

May 3, 2011 at 12:35 AM
Hi,

one of our unit tests should help you

[Test()]
public void FileTestDirectDownloadUrl()
{
// open the publicFilder
ICloudDirectoryEntry publicFolder = cloudStorage.GetFolder(testBaseFolderServerData);

// get the direct url to the pptx
Uri uri = cloudStorage.GetFileSystemObjectUrl("DirectDownloadTest.pptx", publicFolder);

// target
String temp = Environment.ExpandEnvironmentVariables("%temp%\\deg.pptx");

// download to temp
WebClient cl = new WebClient();

// in the case of webdav we need to add the creds
if (Credentials is WebDavCredentials)
{
WebDavCredentials creds = Credentials as WebDavCredentials;
cl.Credentials = creds.GetCredentials();
}

cl.DownloadFile(uri, temp);

// check if file exists
Assert.That(File.Exists(temp));
}

Dirk

2011/4/25 roginsb <notifications@codeplex.com>

From: roginsb

Is there any sample code or documentation demonstrating how to retrieve an absolute file URL for a file or files in a directory and maintain authentication? I have tried to accomplish this with the following code but a series of oauth variables with the same values are appended to the end of the returned URLs resulting in the nonce variable giving an error when clicking one URL to the next. (https://api-content.dropbox.com/0/files/dropbox/Public/Songs/01%20Bang.mp3?oauth_consumer_key=tph4c68u7fdveor&oauth_nonce=6512554&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1303686904&oauth_token=3xvibo8s1slu3jm&oauth_version=1.0&oauth_signature=sIEdvKddmInVUs6EnuvfWKFGIxY=)

    public DataTable getURLs(String directory)
    {
        DataTable dtFiles = new DataTable();
        dtFiles.Columns.Add("File");
        dtFiles.Columns.Add("URL");

        try
        {
            ICloudDirectoryEntry folder = storage.GetFolder(directory);
      
            foreach (ICloudFileSystemEntry fsentry in folder)
            {
                if (fsentry is ICloudFileSystemEntry)
                {
                    dtFiles.Rows.Add(fsentry.Name, storage.GetFileSystemObjectUrl(fsentry.Name, fsentry.Parent));
                }
            }
        

        // close the cloud storage connection
        if (storage.IsOpened)
        {
            storage.Close();
        }
        }
        catch (Exception e)
        {
        }
        return dtFiles;
    }

Read the full discussion online.

To add a post to this discussion, reply to this email (sharpbox@discussions.codeplex.com)

To start a new discussion for this project, email sharpbox@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Jun 15, 2011 at 7:31 PM

hello, thanks for all quick reply. I' ve tested your code but the output the return to me is a text and is this:

{"revision": 51, "thumb_exists": false, "bytes": 777331, "modified": "Sat, 11 Jun 2011 18:11:05 +0000", "path": "/Public/rec1.mp4", "is_dir": false, "icon": "page_white_film", "root": "dropbox", "mime_type": "video/mp4", "size": "759.1KB"}

 

Is a text and not the content of file, of can i retrieve the content of a file whit absolute url ?

This is th code that i use

 ICloudDirectoryEntry folder =_storage.GetFolder("/Public");       
 Stream inputStream =new MemoryStream();
                            
Uri uri = _storage.GetFileSystemObjectUrl("rec1.mp4", folder);               
 string tmp =(Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments), "tmpbgLarge.txt"));
 var request = (HttpWebRequest) WebRequest.Create (uri);
               
 WebClient cl = new WebClient();
 cl.DownloadFile(uri, tmp );

 

thanks bye

 

 

Jun 15, 2011 at 7:58 PM
Hi,

oh sorry I missunderstood you, what you want to is easy, just check out the following unittest:

[Test()]
public void FileTestDirectDownloadUrl()
{
// open the publicFilder
ICloudDirectoryEntry publicFolder = cloudStorage.GetFolder(testBaseFolderServerData);

// get the direct url to the pptx
Uri uri = cloudStorage.GetFileSystemObjectUrl("DirectDownloadTest.pptx", publicFolder);

// target
String temp = Environment.ExpandEnvironmentVariables("%temp%\\deg.pptx");

// download to temp
WebClient cl = new WebClient();

// in the case of webdav we need to add the creds
if (Credentials is GenericNetworkCredentials)
{
GenericNetworkCredentials creds = Credentials as GenericNetworkCredentials;
cl.Credentials = creds.GetCredential(null, null);
}

cl.DownloadFile(uri, temp);

// check if file exists
Assert.That(File.Exists(temp));
}

Cheers
Dirk

2011/6/15 realex82 <notifications@codeplex.com>

From: realex82

hello, thanks for all quick reply. I' ve tested your code but the output the return to me is a text and is this:

{"revision": 51, "thumb_exists": false, "bytes": 777331, "modified": "Sat, 11 Jun 2011 18:11:05 +0000", "path": "/Public/rec1.mp4", "is_dir": false, "icon": "page_white_film", "root": "dropbox", "mime_type": "video/mp4", "size": "759.1KB"}

Is a text and not the content of file, of can i retrieve the content of a file whit absolute url ?

This is th code that i use

ICloudDirectoryEntry folder =_storage.GetFolder("/Public");
Stream inputStream =new MemoryStream();

Uri uri = _storage.GetFileSystemObjectUrl("rec1.mp4", folder);
string tmp =(Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments), "tmpbgLarge.txt"));
var request = (HttpWebRequest) WebRequest.Create (uri);

WebClient cl = new WebClient();
cl.DownloadFile(uri, tmp );

thanks bye

Read the full discussion online.

To add a post to this discussion, reply to this email (sharpbox@discussions.codeplex.com)

To start a new discussion for this project, email sharpbox@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Aug 12, 2011 at 4:26 AM

I'm looking into this issue, and hitting the same issue. It looks like GetFileSystemObjectUri is returning a ResourceUrl and not a DownloadUrl.

Is this the expected behavior?

And the test just verifies that the file was created, not what the content is/was. Even a size check would possibly show you that you are getting correct, or incorrect data.

Thanks!

Aug 12, 2011 at 11:58 AM
Hi,

yes you are totally right. I fixed this issue in our DropBox provider with check in http://sharpbox.codeplex.com/SourceControl/changeset/changes/78220. The solution will be part of SharpBox 1.1.1. You can also use our trunk to get the solution now :-)

Cheers
Dirk

2011/8/12 szurgot <notifications@codeplex.com>

From: szurgot

I'm looking into this issue, and hitting the same issue. It looks like GetFileSystemObjectUri is returning a ResourceUrl and not a DownloadUrl.

Is this the expected behavior?

And the test just verifies that the file was created, not what the content is/was. Even a size check would possibly show you that you are getting correct, or incorrect data.

Thanks!

Read the full discussion online.

To add a post to this discussion, reply to this email (sharpbox@discussions.codeplex.com)

To start a new discussion for this project, email sharpbox@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com